package com.handinfo.android.game;

import java.io.DataInputStream;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.PointF;
import android.widget.Toast;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.net.GameProtocol;
import com.handinfo.android.core.object.Actor;
import com.handinfo.android.core.object.Animation;
import com.handinfo.android.core.object.Background;
import com.handinfo.android.core.object.Scene;
import com.handinfo.android.core.resource.DWSerializableFactory;
import com.handinfo.android.core.resource.ResHead;
import com.handinfo.android.core.resource.Resource;
import com.handinfo.android.core.resource.ResourceManager;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.game.item.ItemConstants;
import com.handinfo.android.game.item.ItemConsume;
import com.handinfo.android.game.item.ItemEquipment;
import com.handinfo.android.game.item.MailItem;
import com.handinfo.android.game.item.SellItem;
import com.handinfo.android.game.item.Tianming;
import com.handinfo.android.game.skill.RoleCombatSkill;
import com.handinfo.android.game.skill.SkillConstants;
import com.handinfo.android.ui.ChatItem;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.PickItem;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.ui.window.UIBag;
import com.handinfo.android.ui.window.UIFixWindow;
import com.handinfo.android.ui.window.UIHook;
import com.handinfo.android.ui.window.UIMail;
import com.handinfo.android.ui.window.UIMain;
import com.handinfo.android.ui.window.UIWarehouse;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.utils.BinHeapAStar;
import com.handinfo.android.utils.Tools;

public class Role extends GameActor
{
	/** 宠物 */
	public Npc m_pet;
	/** 坐骑 */
	public Actor m_ride;
	/** 宝石光效 */
	public Actor m_effect1, m_effect2;
	/** 称号动画 */
	public Actor m_animAppellation;
	public int m_appType;

	public boolean m_delete = false;// 是否被删除,处在保留期
	public int m_keepDay = 0;// 保留期天数

	public long m_exp = 0;// 当前经验
	public long m_maxExp = 0;// 当前总经验

	public int m_anger = 0; // 当前怒气
	public int m_angerMax = 0; // 最大怒气

	public int m_jinglizhi_zonggong = 0; // 玩家总精力值
	public int m_jinglizhi_shengyu = 0; // 玩家当前所剩精力值

	public byte m_vip_lv = 0;// vip等级
	public String m_appellation = null;// 角色称号
	public byte m_appellation_color = 0;// 颜色值
	public byte m_wanted_type = -1;// 通缉
	public String m_sellTitle = null;// 摆摊标题

	public RoleCombatSkill m_auto_skill = null;// 寻路后施放的技能
	public GameActor m_auto_target = null;// 寻路后施放的目标
	public boolean m_skill_auto = false;

	public int m_shitu_tudilv = 0;//徒弟的最高等级
	public int m_shitu_laoshi = 0;//老师最低等级
	public String m_shitu_guanxi;//师徒关系
	
	public int m_jinbi_num01 = 0;//金币的帮贡
	public int m_jinbi_num02 = 0;//金币的家族成长
	public int m_yuanbao_numMin01 = 0;//元宝 1 帮贡
	public int m_yuanbao_numMin02 = 0;//元宝1  家族成长
	public int m_yuanbao_numMax01 = 0;//元宝100 帮贡
	public int m_yuanbao_numMax02 = 0;//元宝 100 家族成长

	// 寻路
	public boolean m_is_autopath = false;// 是否为自动寻路切图
	public Vector<PointF> m_pathfinding_point = new Vector<PointF>();// 寻路终点集合
	public int m_pathfinding_label = 0;// 寻路终点索引
	public boolean m_pathfinding_pause = false;// 是否暂停
	public boolean m_pathfinding_start = false;// 是否在寻路
	public int[] m_pathfinding_paths = null;// 寻路的路径集合
	public int m_pathfinding_index = 0;
	public long m_pathfinding_id = 0;// 寻路的目标ID
	public byte m_pathfinding_way = 0; // 0:为点击走人 1：为去某个npc那

	// public Vector m_social_list = new Vector();// 社交界面数组
	public CopyOnWriteArrayList<Task> m_drama_list = new CopyOnWriteArrayList<Task>(); // //剧情

	// public ArrayList<Task> m_event_list = new ArrayList<Task>(); ////活动

	public CopyOnWriteArrayList<Task> m_acceptably_list = new CopyOnWriteArrayList<Task>(); // ///可接

	// 副本
	public ArrayList<GameCarbon> m_game_carbon = new ArrayList<GameCarbon>();

	public CopyOnWriteArrayList<MailItem> m_recvMails;// 收件箱

	// 道具CD
	public Hashtable<String, Long[]> m_item_cd = new Hashtable<String, Long[]>();

	/******* 金钱 ********/
	// public long m_money_game = 0;
	// public long m_money_rmb = 0;
	// public long m_money_zhangong = 0;// 战功
	// public long m_money_banggong = 0;// 帮贡

	// /**
	// * 金币
	// */
	// public static final byte GOLD = 0;
	// /**
	// * 元宝
	// */
	// public static final byte YUANBAO = 2;
	// /**
	// * 战功
	// */
	// public static final byte ZHANGONG = 3;
	//
	// /**
	// * 帮贡
	// * */
	// public static final byte BANGGONG = 4;
	public Role()
	{
		super();
		m_type = GameActorConstants.ACTOR_TYPE_ROLE;

		m_collideBox[0] = -9;
		m_collideBox[1] = -9;
		m_collideBox[2] = 10;
		m_collideBox[3] = 10;
		m_activeBox[0] = -40;
		m_activeBox[1] = -100;
		m_activeBox[2] = 40;
		m_activeBox[3] = 0;
	}

	public Role(Resource resource)
	{
		super(resource);
		m_type = GameActorConstants.ACTOR_TYPE_ROLE;

		m_collideBox[0] = -9;
		m_collideBox[1] = -9;
		m_collideBox[2] = 10;
		m_collideBox[3] = 10;
		m_activeBox[0] = -40;
		m_activeBox[1] = -100;
		m_activeBox[2] = 40;
		m_activeBox[3] = 0;
	}

	/**
	 * 更新移动信息（根据服务器传回的数据来移动）
	 */
	public void updateMove()
	{
		switch (m_actionIDNow / DIRECT_NUM) {
			default:
				return;
			case ACTION_STAND:
			case ACTION_MOVE:
			case ACTION_STAND_RIDE:
			case ACTION_MOVE_RIDE:
				break;
		}
		if (this != DWGameManager.getInstance().m_role)
			super.updateMove();
	}

	/**
	 * 克隆对象
	 */
	public Actor clone(Actor actor)
	{
		Role ca = new Role();
		ca.m_scene = actor.m_scene;
		ca.m_anims = new Animation[actor.m_anims.length];
		System.arraycopy(actor.m_anims, 0, ca.m_anims, 0, actor.m_anims.length);
		ca.m_anim = actor.m_anim;
		ca.m_actionIDNow = actor.m_actionIDNow;
		ca.m_actionIDBefore = actor.m_actionIDBefore;
		ca.m_frameId = actor.m_frameId;
		ca.m_frameIndex = actor.m_frameIndex;
		ca.m_frameDuration = actor.m_frameDuration;
		ca.m_actionCycle = actor.m_actionCycle;
		ca.m_actionOver = actor.m_actionOver;
		ca.m_layer = actor.m_layer;
		ca.m_phyLayer = actor.m_phyLayer;
		ca.m_flag = actor.m_flag;
		ca.m_flipX = actor.m_flipX;
		ca.m_flipY = actor.m_flipY;
		ca.m_visible = actor.m_visible;
		ca.m_enabled = actor.m_enabled;
		ca.m_needDraw = actor.m_needDraw;
		ca.m_posX = actor.m_posX;
		ca.m_posY = actor.m_posY;
		ca.m_vX = actor.m_vX;
		ca.m_vY = actor.m_vY;
		ca.m_collideBox = new short[actor.m_collideBox.length];
		System.arraycopy(actor.m_collideBox, 0, ca.m_collideBox, 0,
				actor.m_collideBox.length);
		ca.m_activeBox = new short[actor.m_activeBox.length];
		System.arraycopy(actor.m_activeBox, 0, ca.m_activeBox, 0,
				actor.m_activeBox.length);
		ca.m_parameters = new short[actor.m_parameters.length];
		System.arraycopy(actor.m_parameters, 0, ca.m_parameters, 0,
				actor.m_parameters.length);
		return ca;
	}

	@Override
	public void setAction(int actionIDNext, boolean actionCycle)
	{
		if (m_ride != null) {
			m_ride.setAction(actionIDNext, actionCycle);
		}
		if (m_effect1 != null) {
			m_effect1.setAction(actionIDNext, actionCycle);
		}
		if (m_effect2 != null) {
			m_effect2.setAction(actionIDNext, actionCycle);
		}
		super.setAction(actionIDNext, actionCycle);
	}

	@Override
	public void nextFrame()
	{
		if (m_ride != null) {
			m_ride.nextFrame();
		}
		if (m_effect1 != null) {
			m_effect1.nextFrame();
		}
		if (m_effect2 != null) {
			m_effect2.nextFrame();
		}
		if (m_pet != null) {
			m_pet.nextFrame();
		}
		super.nextFrame();
	}

	/**
	 * 更新位置信息
	 */
	public synchronized void updatePos()
	{
		if (!m_pathfinding_start) {
			bgCollide();
		}
		super.updatePos();
		if (this == (m_scene).m_controlledActor) {
			m_posX = Tools.limit(m_posX, 0 - m_collideBox[0], m_scene.m_bgWidth
					- m_collideBox[2]);
			m_posY = Tools.limit(m_posY, 0 - m_collideBox[1],
					m_scene.m_bgHeight - m_collideBox[3]);
		}
	}

	@Override
	public void drawAnimations(DWGraphics g, int camX, int camY)
	{
		if (m_anims == null || m_anims.length == 0)
			return;
		int x = m_posX - camX;
		int y = m_posY - camY;
		// 坐骑动画单独绘制，不进行统一绘制
		for (int i = 1; i < m_anims.length - 1; i++) {
			switch (i) {
				case ANIM_HEAD:
				case ANIM_UPPER:
				case ANIM_LOWER:
				case ANIM_WEAPON:
					if (m_anims[i] != null) {
						m_anims[i].draw(g, x, y, m_flipX, m_flipY, m_frameIndex);
					}
					break;
			}
			// if (m_anims[i] != null) {
			// m_anims[i].draw(g, x, y, m_flipX, m_flipY, m_frameIndex);
			// }
		}
	}

	/**
	 * 绘制
	 */
	public void draw(DWGraphics g, int camX, int camY)
	{
		try {
			if (!DWGameManager.getSetting_graphics(DWGameManager.设置画面_显示友方玩家)) {
				if (m_scene != null
						&& checkTargetFriend(m_scene.m_controlledActor)
						&& this != m_scene.m_controlledActor) {
					return;
				}
			}
			if (!DWGameManager.getSetting_graphics(DWGameManager.设置画面_显示敌方玩家)) {
				if (m_scene != null
						&& !checkTargetFriend(m_scene.m_controlledActor)
						&& this != m_scene.m_controlledActor) {
					return;
				}
			}
			// 阴影
			switch (m_actionIDNow / DIRECT_NUM) {

				case ACTION_DEAD:
				case ACTION_MOVE_RIDE:
				case ACTION_STAND_RIDE:
				case ACTION_ATTACK1_RIDE:
				case ACTION_ATTACK2_RIDE:
				case ACTION_HEAD:
					break;
				default:
					g.setClip(0, 0, DWGameManager.Screen_Width,
							DWGameManager.Screen_Height);
					if (m_sellTitle != null && !m_sellTitle.equals("")
							&& IconManger.m_sellShop != null) {
						int shopx = m_posX - camX;
						int shopy = m_posY - camY;
						g.drawBitmap(IconManger.m_sellShop, shopx, shopy,
								Tools.HCENTER_VCENTER);
					}
					else {
						g.setColor(GameActorConstants.COLOR_ACTOR_SHADOW);
						g.fillArc(m_posX - camX + m_collideBox[0] * 2, m_posY
								- camY + m_collideBox[1],
								(m_collideBox[2] - m_collideBox[0]) * 2,
								m_collideBox[3] - m_collideBox[1], 0, 360);
					}
					break;

			}
			if (m_scene != null) {
				if (this == ((Scene) m_scene).m_controlledActor.m_targetActor) {
					Scene.s_targetFrame.m_posX = m_posX;
					Scene.s_targetFrame.m_posY = m_posY;
					Scene.s_targetFrame.draw(g, camX, camY);
					Scene.s_targetFrame.nextFrame();
				}
			}

			// 绘制坐骑
			if (m_ride != null) {
				m_ride.m_flipX = m_flipX;
				m_ride.m_posX = m_posX;
				m_ride.m_posY = m_posY;
				m_ride.draw(g, camX, camY);
			}
			super.draw(g, camX, camY);
			if (m_effect1 != null) {
				m_effect1.m_flipX = m_flipX;
				m_effect1.m_posX = m_posX;
				m_effect1.m_posY = m_posY;
				m_effect1.draw(g, camX, camY);
			}
			if (m_effect2 != null) {
				m_effect2.m_flipX = m_flipX;
				m_effect2.m_posX = m_posX;
				m_effect2.m_posY = m_posY;
				m_effect2.draw(g, camX, camY);
			}

			// 名字 称号 家族 VIP 显示
			int offsetY = 10;
			int offsetX = 0;
			int tempX = 0;
			int tempY = 0;
			switch (m_actionIDNow / DIRECT_NUM) {
				case ACTION_MOVE_RIDE:
				case ACTION_STAND_RIDE:
				case ACTION_ATTACK1_RIDE:
				case ACTION_ATTACK2_RIDE:
					offsetY = 60;
					break;
				default:
					offsetY = 10;
					break;
			}
			DWFont font = null;
			int chenghaoY = 0;
			if (DWGameManager.AdpaterType == DWGameManager.AD_HIGH) {
				font = DWFont.getFont(24);
				chenghaoY = font.getHeight();
			}
			else {
				font = DWFont.getDefaultFont();
				chenghaoY = 25;
			}
			int fontValue = font.getHeight();
			if (m_scene != null
					&& this == m_scene.m_controlledActor
					|| DWGameManager
							.getSetting_graphics(DWGameManager.设置画面_显示其他玩家名称)) {
				int nameY = offsetY;
				if (m_sellTitle == null || m_sellTitle.equals("")) {
					//绘制称号
					if (m_appellation != null && !m_appellation.equals("")) {
						tempX = m_posX - camX;
						tempY = m_posY - camY + m_activeBox[1];
						int wordY = offsetY;
						wordY += fontValue;
						if (m_animAppellation != null) {
							offsetY += chenghaoY;
							m_animAppellation.m_posX = tempX;
							m_animAppellation.m_posY = tempY - offsetY;
							g.setClip(0, 0, DWGameManager.Screen_Width,
									DWGameManager.Screen_Height);
							m_animAppellation.draw(g, 0, 0);
						}
						else {
							offsetY += fontValue;
						}
						int color = UIBag.getQualityColor(m_appellation_color);
						g.setClip(0, 0, DWGameManager.Screen_Width,
								DWGameManager.Screen_Height);
						g.drawShadowString(font, m_appellation, Tools.BLACK, color,
								tempX, tempY - wordY, Tools.HCENTER_BOTTOM);
					}
				}
				//绘制名字
				if (m_name != null) {
					offsetX = (int) font.stringWidth(m_name) >> 1;
					tempX = m_posX - camX;
					tempY = m_posY - camY + m_activeBox[1];
					g.setClip(0, 0, DWGameManager.Screen_Width,
							DWGameManager.Screen_Height);
					if ((m_actor_flag & GameActorConstants.ACTOR_FLAG_FIGHT) != 0) {
						g.drawShadowString(font, m_name, Tools.BLACK, Tools.RED,
								tempX, tempY - nameY, Tools.HCENTER_BOTTOM);
					}
					else {
						if (checkTargetFriend(m_scene.m_controlledActor)) {
							g.drawShadowString(font, m_name, Tools.BLACK,
									Tools.WHITE, tempX, tempY - nameY,
									Tools.HCENTER_BOTTOM);
						}
						else {
							g.drawShadowString(font, m_name, Tools.BLACK,
									Tools.ORANGE, tempX, tempY - nameY,
									Tools.HCENTER_BOTTOM);
						}
					}
				}
				//绘制阵营
				if (m_faction > 0 && m_faction < 3) {
					if (IconManger.m_factionIcon[m_faction - 1] != null) {
						offsetX += IconManger.m_factionIcon[m_faction - 1]
								.getWidth() + 1;
						g.drawBitmap(IconManger.m_factionIcon[m_faction - 1],
								tempX - offsetX, tempY - nameY,
								Tools.HCENTER_BOTTOM);
					}
				}
				//绘制VIP
				if (m_vip_lv > 0
						&& (m_vip_lv - 1) < IconManger.m_vipIcon.length) {
					if (IconManger.m_vipIcon[m_vip_lv - 1] != null) {
						offsetX += IconManger.m_vipIcon[m_vip_lv - 1]
								.getWidth() + 1;
						g.drawBitmap(IconManger.m_vipIcon[m_vip_lv - 1], tempX
								- offsetX, tempY - nameY,
								Tools.HCENTER_BOTTOM);
					}
				}
				//绘制售卖或者家族和通缉
				if (m_sellTitle != null && !m_sellTitle.equals("")) {
					offsetY += fontValue + 6;
					int color = 0xfff7fe38;
					int wcolor = 0xff590003;
					g.setClip(0, 0, DWGameManager.Screen_Width,
							DWGameManager.Screen_Height);
					if (IconManger.m_sellTitle != null) {
						float Width = font.stringWidth(
								m_sellTitle) + 30;
						float Height = IconManger.m_sellTitle.getHeight();
						float lowh = Height - fontValue;
						if (lowh > 0) {
							lowh = (int) lowh >> 1;
						}
						else {
							lowh = 0;
						}
						g.drawBitmap(IconManger.m_sellTitle, tempX, tempY
								- offsetY + lowh, Width, Height,
								Tools.HCENTER_BOTTOM);
					}
					g.drawShadowString(font, m_sellTitle, wcolor, color, tempX, tempY
							- offsetY, Tools.HCENTER_BOTTOM);
				}
				else {
					if (m_family_name != null && !m_family_name.equals("")) {
						offsetY += fontValue;
						g.setClip(0, 0, DWGameManager.Screen_Width,
								DWGameManager.Screen_Height);
						g.drawShadowString(font, m_family_name, Tools.BLACK,
								Tools.JIAZU, tempX, tempY - offsetY,
								Tools.HCENTER_BOTTOM);
					}
					if (m_wanted_type > -1 && m_wanted_type < 4
							&& IconManger.m_wantedIcon[m_wanted_type] != null) {
						offsetX = (IconManger.m_wantedIcon[m_wanted_type]
								.getWidth() >> 1);
						offsetY += IconManger.m_wantedIcon[m_wanted_type]
								.getHeight() - 10;
						g.drawBitmap(IconManger.m_wantedIcon[m_wanted_type],
								tempX, tempY - offsetY, Tools.HCENTER_BOTTOM);
					}
				}

				if (m_pathfinding_start && !m_pathfinding_pause) {
					offsetY += fontValue;
					g.setClip(0, 0, DWGameManager.Screen_Width,
							DWGameManager.Screen_Height);
					g.drawShadowString(font, "自动寻路中.....", Tools.BLACK, Tools.RED,
							tempX, tempY - offsetY, Tools.HCENTER_BOTTOM);
				}
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	// /////////////////////////////////////////////////////////////
	// // 快捷栏相关
	public String[] m_shortcut;

	public static final int SHORTCUT_SKILL0 = 0;
	public static final int SHORTCUT_SKILL1 = 1;
	public static final int SHORTCUT_SKILL2 = 2;
	public static final int SHORTCUT_SKILL3 = 3;
	public static final int SHORTCUT_CONSUME = 4;
	public static final int SHORTCUT_RIDE = 5;

	/**
	 * 初始化快捷栏
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void initShortcut(DataInputStream dis) throws IOException
	{
		int size = dis.readByte();
		m_shortcut = new String[size];
		for (int i = 0; i < size; i++) {
			m_shortcut[i] = dis.readUTF();
		}
	}

	/**
	 * 设置快捷栏
	 * 
	 * @param key
	 * @param index
	 */
	public void setShortcut(String key, int index)
	{
		if (m_shortcut != null) {
			if ((key == null || key.length() == 0)
					&& (m_shortcut[index] == null || m_shortcut[index].length() == 0))
				return;
			if (key != null && m_shortcut[index] != null
					&& key.equals(m_shortcut[index]))
				return;
			m_shortcut[index] = null;
			m_shortcut[index] = key;
			if (key != null) {
				DWGameManager.getInstance().getSendMessage()
						.sendActiveCombatSkill(key, index);
			}
			else {
				DWGameManager.getInstance().getSendMessage()
						.sendActiveCombatSkill("", index);
			}
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateSkillSet();
			}
		}
	}

	/** 称号动画 **/
	public void initAppAnim()
	{
		Animation anim = null;
		if (m_appType > 0) {
			String URL = "/anim/chenghaodh_" + m_appType + ".anim";
			ResHead head = new ResHead(
					DWSerializableFactory.RESOURCE_TYPE_ANIM,
					URL, 1);
			anim = (Animation) (ResourceManager.getInstance().loadResource(
					DWGameManager.getInstance().m_resourceStatic, head));
		}
		m_animAppellation = null;
		if (anim != null) {
			m_animAppellation = new Actor(anim);
			m_animAppellation.activate();
			m_animAppellation.setAction(0, true, true);
		}
	}

	/** 称号动画逻辑 **/
	public void logicAppAnim()
	{
		if (m_appellation != null && !m_appellation.equals("")) {
			if (m_animAppellation != null) {
				if (m_animAppellation != null && m_animAppellation.m_enabled) {
					m_animAppellation.nextFrame();
				}
			}
		}
	}

	/**
	 * 接收设置快捷栏
	 * 
	 * @param key
	 * @param index
	 */
	public void recvSetShortcut(String key, int index)
	{
		if (m_shortcut != null) {
			if ((key == null || key.length() == 0)
					&& (m_shortcut[index] == null || m_shortcut[index].length() == 0))
				return;
			if (key != null && m_shortcut[index] != null
					&& key.equals(m_shortcut[index]))
				return;
			m_shortcut[index] = null;
			m_shortcut[index] = key;
		}
	}

	public IShortcutObject getShortcutObject(int index)
	{
		if (m_shortcut != null) {
			switch (index) {
				case SHORTCUT_SKILL0:
				case SHORTCUT_SKILL1:
				case SHORTCUT_SKILL2:
				case SHORTCUT_SKILL3:
					if (m_shortcut[index] != null
							&& m_shortcut[index].length() != 0) {
						return getCombatSkill(m_shortcut[index]);
					}
					break;
				case SHORTCUT_RIDE:
					if (m_shortcut[index] != null
							&& m_shortcut[index].length() != 0) {
						long guid = Tools.getLong(m_shortcut[index]);
						Item item = getItemByGuidForAllColumn(guid);
						if (item != null) {
							item = item.Clone();
							item.m_dbangding = true;
							item.m_dpinzhi = true;
						}
						return item;
					}
					break;
				case SHORTCUT_CONSUME:
					if (m_shortcut[index] != null
							&& m_shortcut[index].length() != 0) {
						return getShortCutConsume(m_shortcut[index]);
					}
					break;
			}
		}
		return null;
	}

	// // 快捷栏相关
	// /////////////////////////////////////////////////////////////

	// ////////////////////////////////////////////////////////////
	// // 战斗技能相关
	public CopyOnWriteArrayList<RoleCombatSkill> m_roleCombatSkill; // 当前玩家角色的技能列表（包括未学习的）

	public int m_castingTimeCounter; // 施法计时器
	public int m_castingTime; // 施法时间
	public String m_castingContent; // 施法内容
	public String m_castingContentArray; // 施法内容切分成的数组

	public RoleCombatSkill m_buffer_skill = null;// 缓存技能

	/**
	 * 初始化技能
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void initCombatSkill(DataInputStream dis) throws IOException
	{
		if (m_roleCombatSkill == null) {
			m_roleCombatSkill = new CopyOnWriteArrayList<RoleCombatSkill>();
		}
		m_roleCombatSkill.clear();
		int num = dis.readByte();// 技能类别长度 默认0-4
		Tools.debugPrintln("技能列表列表长度 : " + num);
		RoleCombatSkill skill;
		for (int i = 0; i < num; i++) {
			// 获得技能信息
			skill = new RoleCombatSkill();
			skill.m_id = dis.readUTF();
			skill.read(dis);
			Tools.debugPrintln("获得技能" + i + " : " + skill.toString());
			m_roleCombatSkill.add(skill);
		}
		Tools.debugPrintln("技能列表列表长度完成！ ");
	}

	/**
	 * 更新技能
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void updateCombatSkill(DataInputStream dis) throws IOException
	{
		String id = dis.readUTF();
		RoleCombatSkill skill = getCombatSkill(id);
		if (skill != null) {
			skill.read(dis);
		}
		else {
			skill = new RoleCombatSkill();
			skill.m_id = id;
			skill.read(dis);
			m_roleCombatSkill.add(skill);
		}
	}

	/**
	 * 释放
	 */
	public void dispose()
	{
		super.dispose();
		// if (m_roleTeam != null) {
		// m_roleTeam.removeAllElements();
		// }
		// if (m_bag_equipment != null) {
		// for (int i = 0; i < m_bag_equipment.length; i++) {
		// m_bag_equipment[i] = null;
		// }
		// }
		// if (m_bag_goods != null) {
		// for (int i = 0; i < m_bag_goods.length; i++) {
		// m_bag_goods[i] = null;
		// }
		// }
		// m_drama_list.removeAllElements();
		// m_event_list.removeAllElements();
	}

	/**
	 * 深度销毁
	 */
	public void destroy()
	{
		super.destroy();
		// if (m_roleTeam != null) {
		// m_roleTeam.removeAllElements();
		// }
		// if (m_bag_equipment != null) {
		// for (int i = 0; i < m_bag_equipment.length; i++) {
		// m_bag_equipment[i] = null;
		// }
		// }
		// if (m_bag_goods != null) {
		// for (int i = 0; i < m_bag_goods.length; i++) {
		// m_bag_goods[i] = null;
		// }
		// }
		// m_drama_list.removeAllElements();
		// m_event_list.removeAllElements();
	}

	public static final String[] ROLE_SEX_LIST = { "无", "男", "女" };
	public static final String[] ROLE_VOCATION_LIST = { "不限制", "剑客", "武者", "道士" };
	public static final String[] ROLE_RACE_LIST = { "无", "仙", "妖", "人", "鬼" };

	public byte m_captain = 0;// 该玩家是否为队长 0为不是队长 1为是队长

	public String m_family_name = null;// 家族名
	public byte m_position = 0;// 职位 0成员,1长老,2族长
	public long m_contribution = 0;// 家族的贡献

	public Vector<Role> m_roleTeam = new Vector<Role>();// 队伍信息
	public long m_leaderID = -1;
	public long m_teamID = 0;
	public int m_grade = 0; // 角色等级
	public int m_teamMemberNum = 0;// 队伍里的人数
	public String m_location = null;// 所在位置
	public static final int TEAMMATE_MAX = 4;

	public boolean m_isCasting; // 当前是否在施放战斗技能
	public boolean m_online = false;// 是否在线

	// public boolean m_delete = false;// 是否被删除,处在保留期
	// public int m_keep_day = 0;// 保留期天数
	// public boolean m_auto_pathfinding = false;// 是否开启施法自动寻路
	// public int m_auto_index = 0;// 寻路的当前索引
	// public int[] m_auto_paths = null;// 寻路的路径

	// public RoleCombatSkill m_auto_skill = null;// 寻路后施放的技能
	// public AbstractGameActor m_auto_target = null;// 寻路后施放的目标

	public void initActor()
	{

	}

	/******* 金钱 ********/
	public long m_gold = 0; // 金币
	public long m_zhangong = 0; // 战功
	public long m_rmb = 0; // 元宝
	public long m_banggong = 0; // 帮贡
	public long m_xiuwei = 0; // 修为
	public long m_jinghun = 0; // 惊魂
	public long m_rongyu = 0;// 荣誉

	/**
	 * 货币类型 - 金币
	 */
	public final static byte CURRENCY_TYPE_GOLD = 0;
	/**
	 * 货币类型 - 战功
	 */
	public final static byte CURRENCY_TYPE_ZHANGONG = 3;
	/**
	 * 货币类型 - 元宝
	 */
	public final static byte CURRENCY_TYPE_RMB = 2;
	/**
	 * 货币类型 - 帮贡
	 */
	public final static byte CURRENCY_TYPE_BANGGONG = 4;
	/**
	 * 货币类型 - 修为
	 */
	public final static byte CURRENCY_TYPE_XIUWEI = 5;
	/**
	 * 货币类型 - 惊魂
	 */
	public final static byte CURRENCY_TYPE_JINGHUN = 1;
	/**
	 * 货币类型 - 荣誉
	 */
	public final static byte CURRENCY_TYPE_RONGYU = 6;

	public static short[] getMoney(long money)
	{
		short[] num = new short[3];
		num[2] = getMoneyGameCopper(money);
		num[1] = getMoneyGameSilver(money);
		num[0] = getMoneyGameGold(money);
		return num;
	}

	/**
	 * 数值与金币的映射规则
	 * 
	 * @param money
	 * @return
	 */
	public static final short getMoneyGameGold(long money)
	{
		return (short) (money / 10000);
	}

	/**
	 * 数值与银币的映射规则
	 * 
	 * @param money
	 * @return
	 */
	public static final short getMoneyGameSilver(long money)
	{
		return (short) ((money % 10000) / 100);
	}

	/**
	 * 数值与铜币的映射规则
	 * 
	 * @param money
	 * @return
	 */
	public static final short getMoneyGameCopper(long money)
	{
		return (short) (money % 100);
	}

	/**
	 * 金银铜转为数值的映射
	 * 
	 * @param money
	 * @return
	 */
	public static long getMoney(short[] money)
	{
		long temp = 0;
		temp += money[0] * 10000;
		temp += money[1] * 100;
		temp += money[2];
		return temp;
	}

	/**
	 * 骑乘
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvDrive(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("接收到服务器数据 ：接收到骑乘信息");
		short state = dis.readShort();
		String info = dis.readUTF();
		if (!info.equals("")) {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, info);
		}
		if (state == 0) {
			return;
		}
	}

	// 聊天
	public Vector<ChatItem> m_list_chats; //全部聊天数据  （除了系统掉落）
	public int m_chats_add_quan = 0;//全部聊天数据  （除了系统掉落） 5秒内新增聊天条数
	public int m_chats_delete_quan = 0;//全部聊天数据  （除了系统掉落）5秒内删除条数

	public Vector[] m_chatList = new Vector[9]; //各个频道的数据
	public int[] m_chats_add = new int[9];// 子频道5秒内新增聊天条数
	public int[] m_chats_delete = new int[9];// 子频道5秒内删除条数
	public boolean m_is_update_chat = false;// 是否更新聊天栏

	public static int MAXNUM_CHATLIST = 300;// 聊天频道掺入内容最大数目，插入的时候需要判断当前数目（除了系统掉落）
	public int[] m_maxnum = new int[] { 200, 50, 50, 50, 50, 100, 50, 50, 50 };// 子频道聊天频道掺入内容最大数目，插入的时候需要判断当前数目（除了系统掉落）

	/**
	 * 重置聊天添加和删除的数量
	 */
	public void resetChatsUpdateNum()
	{
		if (m_chats_add != null) {
			int[] adds = m_chats_add;
			for (int i = 0; i < adds.length; i++) {
				adds[i] = 0;
			}
		}
		if (m_chats_delete != null) {
			int[] dels = m_chats_delete;
			for (int i = 0; i < dels.length; i++) {
				dels[i] = 0;
			}
		}
		m_chats_add_quan = 0;
		m_chats_delete_quan = 0;
	}

	/**
	 * 获得相应类型的聊天记录
	 * 
	 * @param type
	 * @return
	 */
	public final ChatItem[] getChatItemFitType(byte type)
	{
		if (type == ChatItem.TYPE_QUAN) {
			if (m_list_chats == null) {
				m_list_chats = new Vector<ChatItem>();
			}
			int size = m_list_chats.size();
			if (size == 0) {
				return null;
			}
			else {
				ChatItem[] items = new ChatItem[m_chats_add_quan];
				for (int i = 0; i < m_chats_add_quan; i++) {
					if (size - m_chats_add_quan + i >= 0) {
						items[i] = (ChatItem) m_list_chats.get(size - m_chats_add_quan + i);
					}
					else {
						Tools.debugPrintln("得到聊天信息异常 : " + 0);
					}
				}
				return items;
			}

		}
		else {
			Vector<ChatItem> typechats;
			if (type == ChatItem.TYPE_FALL) {
				typechats = m_chatList[ChatItem.TYPE_XI];
				if (typechats == null) {
					typechats = new Vector<ChatItem>();
					m_chatList[ChatItem.TYPE_XI] = typechats;
				}
				int size = typechats.size();
				if (size == 0) {
					return null;
				}
				else {
					int addsize = m_chats_add[ChatItem.TYPE_XI];
					ChatItem[] items = new ChatItem[addsize];
					for (int i = 0; i < addsize; i++) {
						if (size - addsize + i >= 0) {
							items[i] = (ChatItem) typechats.get(size - addsize + i);
						}
						else {
							Tools.debugPrintln("得到聊天信息异常 : " + 1);
						}
					}
					return items;
				}
			}
			else {
				typechats = m_chatList[type];
				if (typechats == null) {
					typechats = new Vector<ChatItem>();
					m_chatList[type] = typechats;
				}
				int size = typechats.size();
				if (size == 0) {
					return null;
				}
				else {
					int addsize = m_chats_add[type];
					ChatItem[] items = new ChatItem[addsize];
					for (int i = 0; i < addsize; i++) {
						if (size - addsize + i >= 0) {
							items[i] = (ChatItem) typechats.get(size - addsize + i);
						}
						else {
							Tools.debugPrintln("得到聊天信息异常 : " + 2);
						}
					}
					return items;
				}
			}
		}
//		ArrayList<ChatItem> list = new ArrayList<ChatItem>();
//		for (int i = 0; i < size; i++) {
//			ChatItem item = (ChatItem) m_list_chats.elementAt(i);
//			if (type == ChatItem.TYPE_QUAN) {
//				if (item.m_type != ChatItem.TYPE_FALL) {
//					list.add(item);
//				}
//			} else if (type == ChatItem.TYPE_XI) {
//				if (ChatItem.TYPE_XI == item.m_type
//						|| ChatItem.TYPE_FALL == item.m_type) {
//					list.add(item);
//				}
//			} else if (type == item.m_type) {
//				list.add(item);
//			}
//			// Tools.debugPrintln("get chatitem type=" + type + ":"
//			// + item.m_content);
//		}
//		size = list.size();
//		if (size <= 0) {
//			return null;
//		}
//		ChatItem[] items = new ChatItem[size];
//		for (int i = 0; i < size; i++) {
//			items[i] = (ChatItem) list.get(i);
//		}
//		return items;
	}

	/**
	 * 加入到聊天系统
	 * 
	 * @param item
	 */
	public static boolean m_siliao_ima_flag = true;

	public void addToChat(ChatItem item)
	{
		Vector<ChatItem> typechats;
		if (item.m_type == ChatItem.TYPE_FALL) {
			typechats = m_chatList[ChatItem.TYPE_XI];
			if (typechats == null) {
				typechats = new Vector<ChatItem>();
				m_chatList[ChatItem.TYPE_XI] = typechats;
			}
		}
		else {
			typechats = m_chatList[item.m_type];
			if (typechats == null) {
				typechats = new Vector<ChatItem>();
				m_chatList[item.m_type] = typechats;
			}
		}
		if (m_list_chats == null) {
			m_list_chats = new Vector<ChatItem>();
		}
		if ((item.m_type == ChatItem.TYPE_WORLD && !DWGameManager
				.getSetting_system(DWGameManager.设置系统_世界频道))
				|| (item.m_type == ChatItem.TYPE_FAMILY && !DWGameManager
						.getSetting_system(DWGameManager.设置系统_家族频道))
				|| (item.m_type == ChatItem.TYPE_TEAM && !DWGameManager
						.getSetting_system(DWGameManager.设置系统_队伍频道))
				|| (item.m_type == ChatItem.TYPE_SI && !DWGameManager
						.getSetting_system(DWGameManager.设置系统_私聊频道))) {
			Tools.debugPrintln("聊天类型" + item.m_type + "被屏蔽此聊天信息不接收!");
		}
		else {
			Tools.debugPrintln("addToChat : " + item.m_type);
			if (item.m_type != ChatItem.TYPE_FALL) {
				if (m_list_chats.size() == Role.MAXNUM_CHATLIST) {
					ChatItem ci = m_list_chats.get(0);
					m_chats_delete_quan++;
					m_list_chats.removeElementAt(0);// 移除第一条
				}
			}
			if (item.m_type == ChatItem.TYPE_FALL) {
				if (typechats.size() == m_maxnum[ChatItem.TYPE_XI]) {
					ChatItem ciType = typechats.get(0);
					m_chats_delete[ChatItem.TYPE_XI]++;
					typechats.removeElementAt(0);
				}
			}
			else {
				if (typechats.size() == m_maxnum[item.m_type]) {
					ChatItem ciType = typechats.get(0);
					m_chats_delete[ciType.m_type]++;
					typechats.removeElementAt(0);
				}
			}
			if (item.m_type == ChatItem.TYPE_FALL) {
				if (m_chats_add[ChatItem.TYPE_XI] < m_maxnum[ChatItem.TYPE_XI]) {
					m_chats_add[ChatItem.TYPE_XI]++;
				}
			}
			else {
				if (m_chats_add[ChatItem.TYPE_XI] < m_maxnum[item.m_type]) {
					m_chats_add[item.m_type]++;
				}
			}
			m_is_update_chat = true;
			if (item.m_type == ChatItem.TYPE_SI) {
				if (!DWControlsManager.getInstance().contains(
						UIWindows.getInstance().m_liaotian.m_liaotian_Frame)) {
					// m_MainImageBox[m_main_liaotiananniu].setBackground(m_main_siliao,
					// true);
					UIMain main = UIWindows.getMain();
					main.m_MainImageBox[main.m_main_liaotiananniu].setBackground(main.m_main_siliao, false);
					m_siliao_ima_flag = false;
				}
			}
			typechats.add(item);
			if (item.m_type != ChatItem.TYPE_FALL) {
				if (m_chats_add_quan < MAXNUM_CHATLIST) {
					m_chats_add_quan++;
					m_list_chats.addElement(item);// 将最后一条加入									
				}
			}
			// Tools.debugPrintln(item.m_content);
		}
		// if (UIWindows.getInstance().m_liaotian != null) {
		// UIWindows.getInstance().m_liaotian.Update();
		// }
		// UIMain.updateChat();
	}

	/**
	 * 逻辑
	 */
	public void logic()
	{
		if (this == m_scene.m_controlledActor) {
			// 寻路逻辑是否合法
			// sreachPathSafety();
			checkMySelfInAnyDistance();

			// 技能和物品cooldown
			cooldown();

			// 施法计时
			castingTimeTick();

			// 处理目标过远
			dealTargetActorFar();

			if (UIHook.s_autoHook) {
				// 挂机选取最近的目标
				changeTargetMonsterAuto();
				// VIP自动修理
				if (m_vip_lv > 1 && UIHook.s_autoRepair && checkEquipDurable()) {
					if (++UIHook.s_autoRepairTime >= DWGameManager.FRAME_PER_SECOND * 60) {
						DWGameManager.getInstance().getSendMessage().sendAutoFixAllForVIP();
						UIHook.s_autoRepairTime = 0;
					}
				}
			}
			else {
				// 自动选取最近的目标
				if (DWGameManager.getInstance().m_scene_pk == 2) {
					changeTargetActorAutoForPK();
				}
				else {
					changeTargetActorAuto();
				}
			}

			// 自动寻路
			sceneAutoPathfinding();
			// 技能自动寻路
			autoPathfindingLogic();

			if (UIHook.s_autoHook) {
				// 挂机自动战斗
				autoHookFight();
			}
			else {
				// 自动战斗
				autoFight();
			}
		}
		super.logic();

		if (m_pet != null) {
			m_pet.updatePos();
			m_pet.petlogic(m_posX, m_posY);
			m_pet.nextFrame();
		}
		// 称号逻辑
		logicAppAnim();

		switch (m_actionIDNow / GameActorConstants.DIRECT_NUM) {
			case ACTION_DEAD:
				break;
			case ACTION_ATTACK1:
			case ACTION_ATTACK2:
			case ACTION_ATTACK1_RIDE:
			case ACTION_ATTACK2_RIDE:
				if (m_actionOver & !m_actionCycle) {
					stay(m_direct);
				}
				break;
		}

	}

	public void logicItemCd()
	{
		if (m_item_cd == null) {
			return;
		}
		for (Iterator it = m_item_cd.keySet().iterator(); it.hasNext();) {
			String key = (String) it.next();
			Long[] value = (m_item_cd.get(key));
			int size = value.length;
			long[] array = new long[size];
			for (int i = 0; i < size; i++) {
				array[i] = value[i].longValue();
			}
			if (System.currentTimeMillis() - array[0] >= array[1] * 1000) {
				m_item_cd.remove(key);
			}
		}
	}

	/**
	 * 查出当前装备栏内所有耐久损耗的装备
	 * @return
	 */
	public ArrayList<Item> getEquipDurableList()
	{
		Cell[] cells = getCells(Cell.TYPE_COLUMN_EQUIP);
		ArrayList<Item> list = new ArrayList<Item>();
		if (cells != null) {
			for (Cell cell : cells) {
				if (cell != null
						&& cell.m_item != null
						&& cell.m_item instanceof ItemEquipment) {
					ItemEquipment item = (ItemEquipment) cell.m_item;
					if (item.m_maxDurable > 0 && item.m_nowDurable == 0) {
						list.add(item);
					}
				}
			}
		}
		return list;
	}

	/**
	 * 判断当前有没有需要修理的装备
	 * @return
	 */
	public boolean checkEquipDurable()
	{
		boolean flag = false;
		Cell[] cells = getCells(Cell.TYPE_COLUMN_EQUIP);
		if (cells != null) {
			for (Cell cell : cells) {
				if (cell != null
						&& cell.m_item != null
						&& cell.m_item instanceof ItemEquipment) {
					ItemEquipment item = (ItemEquipment) cell.m_item;
					if (item.m_maxDurable > 0 && item.m_nowDurable == 0) {
						flag = true;
						break;
					}
				}
			}
		}
		return flag;
	}

	/***
	 * 判断角色是否是摆盘状态
	 * 
	 * @return
	 */
	public boolean isSellStatus()
	{
		boolean flag = false;
		if (UIWindows.getInstance().m_baitan != null
				&& UIWindows.getInstance().m_baitan.SELL_TYPE) {
			flag = true;
		}
		if (m_sellTitle != null && !m_sellTitle.equals("")) {
			flag = true;
		}
		return flag;
	}

	public boolean isOtherSellStatus()
	{
		boolean flag = false;
		if (m_sellTitle != null && !m_sellTitle.equals("")) {
			flag = true;
		}
		return flag;
	}

	// private void sreachPathSafety(){
	// if(m_pathfinding_start && !m_pathfinding_pause){
	// if(m_pathfinding_point == null || m_pathfinding_point.size() < 1){
	// resetAutoPathfinding();
	// stay(m_direct);
	// }
	// }
	// }

	private void autoPathfindingLogic()
	{
		if (m_skill_auto) {
			Role role = DWGameManager.getInstance().m_role;
			if (m_auto_target == null || role.m_targetActor == null
					|| !role.m_targetActor.equals(m_auto_target)) {
				Tools.debugPrintln("目标被移除,自动寻路结束!");
				resetAutoPathfinding();
				stay(m_direct);
				return;
			}
			if (m_auto_skill == null) {// 采集
				if ((m_posX - m_auto_target.m_posX)
						* (m_posX - m_auto_target.m_posX)
						+ (m_posY - m_auto_target.m_posY)
						* (m_posY - m_auto_target.m_posY) < 32 * 32) {
					if (m_auto_target.m_type == GameActorConstants.ACTOR_TYPE_GATHERING
							|| m_auto_target.m_type == GameActorConstants.ACTOR_TYPE_NPC) {
						m_scene.setTargetActor(m_auto_target);
						DWGameManager.getInstance().getSendMessage()
								.sendNPCList(m_auto_target.m_gameId);
					}
					resetAutoPathfinding();
					stay(m_direct);
				}
			}
			else {// 技能
				if (((m_posX - m_auto_target.m_posX)
						* (m_posX - m_auto_target.m_posX)
						+ (m_posY - m_auto_target.m_posY)
						* (m_posY - m_auto_target.m_posY) < 32 * 32)
						|| role.checkTargetDistance(m_auto_skill, m_auto_target)) {
					stay(m_direct);
					m_scene.setTargetActor(m_auto_target);
					if (role.canUseCombatSkill(m_auto_skill, m_auto_target)) {
						role.useCombatSkill(m_auto_skill);
					}
					resetAutoPathfinding();
				}
			}
		}
	}

	/** 焦点选取判定范围 */
	public static final int TARGET_RANGE_FIND = 180 * 180;
	/** 自动挂机焦点选取范围 */
	public static final int HOOK_TARGET_RANGE_FIND = 360 * 360;

	/**
	 * 处理目标过远
	 */
	public void dealTargetActorFar()
	{
		if (m_targetActor == null || m_pathfinding_start)
			return;
		int a = Math.abs((m_targetActor.m_posX - m_posX));
		int b = Math.abs((m_targetActor.m_posY - m_posY));
		if (a * a + b * b > DWGameManager.Screen_Width
				* DWGameManager.Screen_Width) {
			m_scene.setTargetActor(null);
		}
	}

	/**
	 * 自动选取最近的目标
	 */
	public void changeTargetActorAutoForPK()
	{
		// // 自动寻路中不判断
		// if (m_pathfinding_start) {
		// return;
		// }
		// 只有当目标为空
		if (m_targetActor != null)
			return;

		GameActor targetActor = null;

		int range = TARGET_RANGE_FIND;

		for (int i = 0; i < m_scene.m_drawList.size(); i++) {
			if (!(m_scene.m_drawList.get(i) instanceof Role))
				continue;
			Role actor = (Role) m_scene.m_drawList.get(i);
			if (actor.isDead() || !actor.m_enabled
					|| actor.m_gameId == m_scene.m_controlledActor.m_gameId
					|| actor.m_vocation == m_scene.m_controlledActor.m_vocation) {
				continue;
			}
			int a = Math.abs((actor.m_posX - m_posX));
			int b = Math.abs((actor.m_posY - m_posY));
			int distance = a * a + b * b;
			if (distance < range) {
				targetActor = actor;
				range = distance;
			}
		}
		m_scene.setTargetActor(targetActor);
	}

	/**
	 * 自动选取最近的目标
	 */
	public void changeTargetActorAuto()
	{
		// 自动寻路中不判断
		if (m_pathfinding_start) {
			return;
		}
		// 只有当目标为空或者目标为npc时才会自动选取最近目标
		if (m_targetActor != null
				&& m_targetActor.m_type != GameActorConstants.ACTOR_TYPE_NPC)
			return;

		switch (m_actionIDNow / GameActorConstants.DIRECT_NUM) {
			case ACTION_MOVE:
			case ACTION_MOVE_RIDE:
			case ACTION_PICK:
			case ACTION_STAND:
			case ACTION_STAND_RIDE:
				break;
			default:
				return;
		}

		GameActor targetActor = null;

		int range = TARGET_RANGE_FIND;

		for (int i = 0; i < m_scene.m_drawList.size(); i++) {
			if (!(m_scene.m_drawList.get(i) instanceof GameActor))
				continue;
			GameActor actor = (GameActor) m_scene.m_drawList.get(i);
			if (actor.isDead() || !actor.m_enabled)
				continue;
			if (actor.m_type == GameActorConstants.ACTOR_TYPE_MONSTER
					|| actor.m_type == GameActorConstants.ACTOR_TYPE_GATHERING
					|| actor.m_type == GameActorConstants.ACTOR_TYPE_NPC) {
				int a = Math.abs((actor.m_posX - m_posX));
				int b = Math.abs((actor.m_posY - m_posY));
				int distance = a * a + b * b;
				if (distance < range) {
					targetActor = actor;
					range = distance;
				}
			}
		}
		m_scene.setTargetActor(targetActor);
	}

	/**
	 * 自动挂机选取最近的目标
	 */
	public void changeTargetMonsterAuto()
	{
		// 自动寻路中不判断
		if (m_pathfinding_start) {
			return;
		}
		// 如果没有目标 或者目标不是怪物 自动寻找距离挂机点最近的怪
		if (m_targetActor != null
				&& m_targetActor.m_type == GameActorConstants.ACTOR_TYPE_MONSTER
				&& m_targetActor.m_hp > 0)
			return;

		GameActor targetActor = null;

		int range = HOOK_TARGET_RANGE_FIND;
		int posx = m_posX;
		int posy = m_posY;
		if (UIWindows.getInstance().m_hook != null) {
			posx = UIWindows.getInstance().m_hook.m_posx;
			posy = UIWindows.getInstance().m_hook.m_posy;
		}

		for (int i = 0; i < m_scene.m_drawList.size(); i++) {
			if (!(m_scene.m_drawList.get(i) instanceof GameActor))
				continue;
			GameActor actor = (GameActor) m_scene.m_drawList.get(i);
			if (actor.isDead() || !actor.m_enabled)
				continue;
			if (actor.m_type == GameActorConstants.ACTOR_TYPE_MONSTER) {
				int a = Math.abs((actor.m_posX - posx));
				int b = Math.abs((actor.m_posY - posy));
				int distance = a * a + b * b;
				if (distance < range) {
					targetActor = actor;
					range = distance;
				}
			}
		}
		m_scene.setTargetActor(targetActor);

		// 没有目标回到挂机开始点
		if (targetActor == null) {
			if (UIWindows.getInstance().m_hook != null) {
				// 只有目标不在原点添加到寻路
				if (UIWindows.getInstance().m_hook.checkPosXY(m_posX, m_posY)) {
					return;
				}
				PointF pointf = new PointF(posx, posy);
				doPath(pointf);
				pointf = null;
			}
		}
	}

	/**
	 * 角色是否能移动
	 * 
	 * @return
	 */
	public boolean canMove()
	{
		if (this != m_scene.m_controlledActor)
			return true;
		if (m_status == ACTOR_STATUS_DEAD)
			return false;
		if ((m_action & GameActorConstants.ACTOR_ACTION_FORBIT_MOVE) != 0)
			return false;
		if (m_curCombatSkill == null)
			return true;
		if (!m_curCombatSkill.isActive())
			return true;
		switch (m_curCombatSkill.getCurStep()) {
			case SkillConstants.阶段_施法:
				return false;
			default:
				return true;
		}
		// switch (m_actionIDNow / DIRECT_NUM) {
		// case ACTION_ATTACK1:
		// case ACTION_ATTACK2:
		// if (m_curCombatSkill == null)
		// return true;
		// if (m_curCombatSkill.m_castSrcActionId == actionID
		// && (m_curCombatSkill.m_type == SkillConstants.瞬发 ||
		// m_curCombatSkill.m_type == SkillConstants.吟唱)) {
		// result = false;
		// }
		// break;
		// default:
		// break;
		// }
	}

	public synchronized void move(float vx, float vy, float v)
	{
		if (!canMove())
			return;

		if (m_isride) {
			int action = ACTION_MOVE_RIDE * DIRECT_NUM;

			double sinD = vy / v;

			int direct = -1;
			double PI = Math.PI;
			if (sinD >= Math.sin(-PI / 8) && sinD <= Math.sin(PI / 8) && vx > 0) {
				direct = DIRECT_E;
			}
			else if (sinD >= Math.sin(PI / 8) && sinD <= Math.sin(PI * 3 / 8)
					&& vx > 0) {
				direct = DIRECT_ES;
			}
			else if (sinD >= Math.sin(PI * 3 / 8)) {
				direct = DIRECT_S;
			}
			else if (sinD >= Math.sin(PI * 7 / 8)
					&& sinD <= Math.sin(PI * 5 / 8) && vx < 0) {
				direct = DIRECT_SW;
			}
			else if (sinD >= Math.sin(-PI * 7 / 8)
					&& sinD <= Math.sin(PI * 7 / 8) && vx < 0) {
				direct = DIRECT_W;
			}
			else if (sinD >= Math.sin(-PI * 5 / 8)
					&& sinD <= Math.sin(-PI * 7 / 8) && vx < 0) {
				direct = DIRECT_WN;
			}
			else if (sinD <= Math.sin(-PI * 5 / 8)) {
				direct = DIRECT_N;
			}
			else if (sinD >= Math.sin(-PI * 3 / 8)
					&& sinD <= Math.sin(-PI / 8) && vx > 0) {
				direct = DIRECT_NE;
			}

			switch (direct) {
				case DIRECT_E:
					m_flipX = false;
					setAction(action + direct, vx, vy, true, false);
					break;
				case DIRECT_S:
					if (vx < 0) {
						m_flipX = true;
					}
					setAction(action + direct, vx, vy, true, false);
					break;
				case DIRECT_W:
					m_flipX = false;
					setAction(action + direct, vx, vy, true, false);
					break;
				case DIRECT_N:
					if (vx < 0) {
						m_flipX = true;
					}
					setAction(action + direct, vx, vy, true, false);
					break;
				case DIRECT_ES:
					m_flipX = false;
					setAction(action + DIRECT_E, vx, vy, true, false);
					break;
				case DIRECT_SW:
					m_flipX = false;
					setAction(action + DIRECT_W, vx, vy, true, false);
					break;
				case DIRECT_WN:
					m_flipX = true;
					setAction(action + DIRECT_E, vx, vy, true, false);
					break;
				case DIRECT_NE:
					m_flipX = false;
					setAction(action + DIRECT_E, vx, vy, true, false);
					break;
			}
		}
		else {
			super.move(vx, vy, v);
		}

		if (this == m_scene.m_controlledActor) {
			if (m_isCasting) {
				m_isCasting = false;
				// DWGameManager.getInstance().m_game_message.sendCastCancel();
				stopCasting();
				stopCastingDescription();
			}
			if (m_scene.m_interact_start) {
				m_scene.endNPCInteract();
				stopCasting();
				stopCastingDescription();
			}
		}
	}

	public synchronized void stay(int direct)
	{
		if (m_isride) {
			setAction(ACTION_STAND_RIDE * DIRECT_NUM + direct, 0, 0, true,
					false);
		}
		else {
			setAction(ACTION_STAND * DIRECT_NUM + direct, 0, 0, true, false);
		}
	}

	public void startCasting(int time)
	{
		m_castingTimeCounter = time;
		m_castingTime = time;
		// 保证在开始绘制前已经赋值
		// UiManager.getInstance().castingChanged(true);
		// UIMain.updataCasting(true);
	}

	public void stopCasting()
	{
		// 保证在关闭绘制后再清零
		// UiManager.getInstance().castingChanged(false);
		// UIMain.updataCasting(false);
		m_castingTime = 0;
		m_castingTimeCounter = 0;
	}

	public void startCastingDescription(String content)
	{
		// 保证在关闭绘制后再清零
		// UiManager.getInstance().castingDescpChanged(true, content);
		UIWindows.getInstance().m_main.setBarTotal(content, m_castingTime
				* DWGameManager.FRAME_PER_SECOND);
		// UIWindows.getInstance().m_main.setBarTotal(str, x, total)
		// UIMain.updataCastingDescp(true, content);
	}

	public void stopCastingDescription()
	{
		UIWindows.getInstance().m_main.removeBar();
		// 保证在关闭绘制后再清零
		// UiManager.getInstance().castingDescpChanged(false, null);
		// UIMain.updataCastingDescp(false, null);
		// UIWindows.getInstance().m_main.removeBar();
	}

	/**
	 * 自动攻击
	 */
	public void autoFight()
	{
		if (m_buffer_skill != null && m_targetActor != null
				&& !checkTargetFriend(m_targetActor)) {
			if (canUseCombatSkill(m_buffer_skill, m_targetActor)) {
				useCombatSkill(m_buffer_skill);
			}
			else {
				if (!m_pathfinding_start) {
					RoleCombatSkill skill = getCombatSkill(SkillConstants.ID_GENERAL_SKILL[m_vocation]);
					if (skill != null
							&& canUseCombatSkill(skill, m_targetActor)) {
						useCombatSkill(skill);
					}
				}
			}
		}
		if (m_targetActor == null) {
			m_buffer_skill = null;
		}
	}

	/**
	 * 挂机自动攻击
	 * */
	public void autoHookFight()
	{
		if (m_hp <= (m_hpMax / 3 * 1)) {
			IShortcutObject object = getShortcutObject(SHORTCUT_CONSUME);
			if (object != null && object instanceof Cell) {
				Cell cell = (Cell) object;
				Item item = cell.m_item;
				if (item != null && item instanceof ItemConsume
						&& item.m_type == ItemConstants.道具类型_消耗
						&& item.m_subtype == ItemConstants.消耗_血蓝药) {
					String key = String.valueOf(((ItemConsume) item).m_cd_type);
					if (item.m_num > 0 && !m_item_cd.containsKey(key)) {
						DWGameManager
								.getInstance()
								.getSendMessage()
								.sendOperaterCellMenuCommand(
										GameProtocol.操作菜单_使用,
										(byte) cell.m_column_type, cell.m_index);
					}
					else {
						// TODO 添加显示道具数量不足
						Tools.debugPrintln("快捷键使用消耗道具数量不足！");
					}
				}
			}
		}
		if (m_targetActor != null && !checkTargetFriend(m_targetActor)) {
			RoleCombatSkill skill = getCombatSkill(SkillConstants.ID_GENERAL_SKILL[m_vocation]);
			if (skill == null) {
				Tools.debugPrintln("自动挂机缺少技能");
				return;
			}
			if (canUseCombatSkill(skill, m_targetActor)) {
				useCombatSkill(skill);
			}
		}
	}

	/**
	 * 学习技能
	 * 
	 * @param skill
	 */
	public void learnCombatSkill(RoleCombatSkill skill)
	{
		if (m_xiuwei >= skill.m_need_sp) {
			DWGameManager.getInstance().getSendMessage()
					.sendLearnCombatSkill(skill.m_id);
		}
		else {
			// message
		}
	}

	/**
	 * 使用技能
	 * 
	 * @param m_id_int
	 */
	public void useCombatSkill(RoleCombatSkill skill)
	{
		if (skill == null)
			return;
		if (m_curCombatSkill != null) {
			m_curCombatSkill.deactive();
		}
		m_curCombatSkill = skill;
		m_curCombatSkill.deactive();

		synPosition();

		Tools.debugPrintln("施放技能: " + skill.m_name);

		switch (skill.m_type) {
			case SkillConstants.绝技:
			case SkillConstants.瞬发: {
				skill.setCaster(this);
				if (m_targetActor != null) {
					changeDirectToTarget(m_targetActor);
					skill.setTarget(m_targetActor);
					DWGameManager.getInstance().getSendMessage()
							.sendCastSkill(skill.m_id, m_targetActor.m_gameId);
				}
				else {
					skill.setTarget(this);
					DWGameManager.getInstance().getSendMessage()
							.sendCastSkill(skill.m_id, m_gameId);
				}
				skill.active(m_scene, SkillConstants.阶段_施法);
				break;
			}
			case SkillConstants.吟唱: {
				skill.setCaster(this);
				if (m_targetActor != null) {
					changeDirectToTarget(m_targetActor);
					skill.setTarget(m_targetActor);
					DWGameManager.getInstance().getSendMessage()
							.sendSingSkill(skill.m_id, m_targetActor.m_gameId);

				}
				else {
					skill.setTarget(this);
					DWGameManager.getInstance().getSendMessage()
							.sendSingSkill(skill.m_id, m_gameId);
				}

				skill.active(m_scene, SkillConstants.阶段_吟唱);

				m_isCasting = true;
				startCasting(((RoleCombatSkill) m_curCombatSkill).m_castingTime);
				startCastingDescription(((RoleCombatSkill) m_curCombatSkill).m_name);
				m_castingTimeCounter = ((RoleCombatSkill) m_curCombatSkill).m_castingTime;
				m_castingTime = ((RoleCombatSkill) m_curCombatSkill).m_castingTime;
				break;
			}
		}
		skill.m_lastUsedTime = System.currentTimeMillis();
		initAutoAttack(skill);
	}

	/**
	 * 是否能施放技能
	 * 
	 * @param skill
	 * @param targets
	 * @return
	 */
	public boolean canUseCombatSkill(RoleCombatSkill skill, GameActor target)
	{
		if (m_pathfinding_start && !m_pathfinding_pause) {
			return false;
		}

		if (skill == null) {
			return false;
		}

		if (skill.m_type == SkillConstants.被动)
			return false;

		// 死亡状态
		if (m_status == ACTOR_STATUS_DEAD) {
			return false;
		}

		// 禁止施法
		if ((m_action & GameActorConstants.ACTOR_ACTION_FORBIT_SKILL) != 0) {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_A, "你处于禁止施法中");
			return false;
		}

		// 正在施法
		if (m_curCombatSkill != null && m_curCombatSkill.isActive()) {
			return false;
		}
		// CD
		if (System.currentTimeMillis() - skill.m_lastUsedTime < skill.m_cd
				* DWGameManager.SECOND) {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_A, "技能正在冷却中");
			return false;
		}
		// 消耗
		if (m_mp < skill.m_consumption) {
			return false;
		}

		if (!checkTarget(skill, target)) {
			return false;
		}

		// // 需要选中目标的技能要判断距离
		// if (!checkTargetDistance(skill, target)) {
		// return false;
		// }
		return true;
	}

	/**
	 * 释放技能是根据目标以及buf状态进行一些判断和处理
	 * 
	 * @param skill
	 * @param target
	 * @return
	 */
	public boolean checkTarget(RoleCombatSkill skill, GameActor target)
	{
		if (target == null) {
			switch (skill.m_targetType) {
			// 以下不需要目标,直接返回true
				case SkillConstants.TARGET_TYPE_ALL:
				case SkillConstants.TARGET_TYPE_ENEMY_ALL:
				case SkillConstants.TARGET_TYPE_FRIEND_ALL:
				case SkillConstants.TARGET_TYPE_S_SURROUND_ALL:
				case SkillConstants.TARGET_TYPE_S_SURROUND_ENEMY:
				case SkillConstants.TARGET_TYPE_S_SURROUND_FRIEND:
				case SkillConstants.TARGET_TYPE_SELF:
				case SkillConstants.TARGET_TYPE_TEAMMATE_ALL:
					return true;
				default:
					return false;
			}
		}
		else {
			// 友方
			if ((target.m_actor_flag & GameActorConstants.ACTOR_FLAG_FIGHT) == 0) {
				switch (skill.m_targetType) {
				// 以下不需要目标,直接返回true
					case SkillConstants.TARGET_TYPE_ALL:
					case SkillConstants.TARGET_TYPE_ENEMY_ALL:
					case SkillConstants.TARGET_TYPE_FRIEND_ALL:
					case SkillConstants.TARGET_TYPE_S_SURROUND_ALL:
					case SkillConstants.TARGET_TYPE_S_SURROUND_ENEMY:
					case SkillConstants.TARGET_TYPE_S_SURROUND_FRIEND:
					case SkillConstants.TARGET_TYPE_SELF:
					case SkillConstants.TARGET_TYPE_TEAMMATE_ALL:
						return true;
						// 目标必须是友方死的
					case SkillConstants.TARGET_TYPE_FRIEND_SINGLE_DEAD:
						if (target.m_status != ACTOR_STATUS_DEAD) {
							((Scene) m_scene).addMessage(SKILL_HINT_LIVE_TARGET,
									Tools.RED, Tools.BLACK);
							return false;
						}
						break;
					// 目标必须是友方活的
					case SkillConstants.TARGET_TYPE_FRIEND_SINGLE:
					case SkillConstants.TARGET_TYPE_T_SURROUND_FRIEND:
						if (target.m_status == ACTOR_STATUS_DEAD) {
							((Scene) m_scene).addMessage(SKILL_HINT_DEAD_TARGET,
									Tools.RED, Tools.BLACK);
							return false;
						}
						break;
					// 有目标即可
					case SkillConstants.TARGET_TYPE_T_LINE_ALL:
					case SkillConstants.TARGET_TYPE_T_SURROUND_ALL:
						break;
					default:
						return false;
				}
			}
			else {
				switch (skill.m_targetType) {
				// 以下不需要目标,直接返回true
					case SkillConstants.TARGET_TYPE_ALL:
					case SkillConstants.TARGET_TYPE_ENEMY_ALL:
					case SkillConstants.TARGET_TYPE_FRIEND_ALL:
					case SkillConstants.TARGET_TYPE_S_SURROUND_ALL:
					case SkillConstants.TARGET_TYPE_S_SURROUND_ENEMY:
					case SkillConstants.TARGET_TYPE_S_SURROUND_FRIEND:
					case SkillConstants.TARGET_TYPE_SELF:
					case SkillConstants.TARGET_TYPE_TEAMMATE_ALL:
						return true;
						// 目标必须是敌方
					case SkillConstants.TARGET_TYPE_ENEMY_SINGLE:
					case SkillConstants.TARGET_TYPE_T_SURROUND_ENEMY:
					case SkillConstants.TARGET_TYPE_T_LINE_ENEMY:
						if (target.isDead()) {
							((Scene) m_scene).addMessage(SKILL_HINT_DEAD_TARGET,
									Tools.RED, Tools.BLACK);
							return false;
						}
						break;
					// 有目标即可
					case SkillConstants.TARGET_TYPE_T_LINE_ALL:
					case SkillConstants.TARGET_TYPE_T_SURROUND_ALL:
						break;
					default:
						return false;
				}
			}
		}

		// switch (skill.m_targetType) {
		// // 以下不需要目标,直接返回true
		// case SkillConstants.TARGET_TYPE_ALL:
		// case SkillConstants.TARGET_TYPE_ENEMY_ALL:
		// case SkillConstants.TARGET_TYPE_FRIEND_ALL:
		// case SkillConstants.TARGET_TYPE_S_SURROUND_ALL:
		// case SkillConstants.TARGET_TYPE_S_SURROUND_ENEMY:
		// case SkillConstants.TARGET_TYPE_S_SURROUND_FRIEND:
		// case SkillConstants.TARGET_TYPE_SELF:
		// case SkillConstants.TARGET_TYPE_TEAMMATE_ALL:
		// return true;
		// // 目标必须是敌方
		// case SkillConstants.TARGET_TYPE_ENEMY_SINGLE:
		// case SkillConstants.TARGET_TYPE_T_SURROUND_ENEMY:
		// case SkillConstants.TARGET_TYPE_T_LINE_ENEMY:
		// if (target == null) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED,
		// // Tools.BLACK);
		// return false;
		// }
		// else if (checkTargetFriend(target)) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_INVALID_TARGET,
		// // Tools.RED, Tools.BLACK);
		// return false;
		// }
		// else if (target.m_status == ACTOR_STATUS_DEAD) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_DEAD_TARGET,
		// // Tools.RED, Tools.BLACK);
		// return false;
		// }
		// break;
		// // 目标必须是友方死的
		// case SkillConstants.TARGET_TYPE_FRIEND_SINGLE_DEAD:
		// if (target == null) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED,
		// // Tools.BLACK);
		// return false;
		// }
		// else if (!checkTargetFriend(target)) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_INVALID_TARGET,
		// // Tools.RED, Tools.BLACK);
		// return false;
		// }
		// else if (target.m_status != ACTOR_STATUS_DEAD) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_LIVE_TARGET,
		// // Tools.RED, Tools.BLACK);
		// return false;
		// }
		// break;
		// // 目标必须是友方活的
		// case SkillConstants.TARGET_TYPE_FRIEND_SINGLE:
		// case SkillConstants.TARGET_TYPE_T_SURROUND_FRIEND:
		// if (target == null) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED,
		// // Tools.BLACK);
		// return false;
		// }
		// else if (!checkTargetFriend(target)) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_INVALID_TARGET,
		// // Tools.RED, Tools.BLACK);
		// return false;
		// }
		// else if (target.m_status == ACTOR_STATUS_DEAD) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_DEAD_TARGET,
		// // Tools.RED, Tools.BLACK);
		// return false;
		// }
		// break;
		// // 有目标即可
		// case SkillConstants.TARGET_TYPE_T_LINE_ALL:
		// case SkillConstants.TARGET_TYPE_T_SURROUND_ALL:
		// if (target == null) {
		// // ((Scene) m_scene).addMessage(SKILL_HINT_NO_TARGET, Tools.RED,
		// // Tools.BLACK);
		// return false;
		// }
		// break;
		// }
		// if ((m_posX - target.m_posX) * (m_posX - target.m_posX)
		// + (m_posY - target.m_posY) * (m_posY - target.m_posY) > skill.m_range
		// * skill.m_range) {
		// return false;
		// }
		// 需要选中目标的技能要判断距离
		if (!checkTargetDistance(skill, target)) {
			return false;
		}
		else {
			return true;
		}
	}

	/**
	 * 检查目标是否在技能范围内
	 * 
	 * @param skill
	 * @param target
	 * @return
	 */
	private boolean checkTargetDistance(RoleCombatSkill skill, GameActor target)
	{
		if (skill.m_range == 0) {
			return true;
		}
		else {
			if ((m_posX - target.m_posX) * (m_posX - target.m_posX)
					+ (m_posY - target.m_posY) * (m_posY - target.m_posY) > (skill.m_range + target.m_underAttack_range)
					* (skill.m_range + target.m_underAttack_range)) {
				if (!skill.equals(m_auto_skill)) {
					// Background background = ((SceneHandler)
					// DWGameManager.getInstance().getGameHandler()).m_scene.m_bg;
					// int targetPos = (target.m_posY >> 4) *
					// background.m_columns + (target.m_posX >> 4);
					// m_auto_paths = BinHeapAStar.findPath(
					// background.getPhyData(), background.m_columns,
					// background.m_rows, (m_posY >> 4) * background.m_columns +
					// (m_posX >> 4), targetPos);
					// Tools.debugPrintln("技能自动寻路开始");
					// if (m_auto_paths != null &&
					// m_auto_paths[m_auto_paths.length - 1] == targetPos) {
					openAutoPathfinding(skill, target);
					// }
					// else {
					// Tools.debugPrintln("目标与寻路结果不同,寻路失败!" + m_auto_paths);
					// }
				}
			}
			else {
				return true;
			}
		}
		return false;
	}

	/**
	 * 检查目标是否在范围内
	 */
	private void checkMySelfInAnyDistance()
	{
		if (m_scene != null && m_scene.m_dname != null
				&& m_scene.m_dname.length > 0) {
			int size = m_scene.m_dname.length;
			int index = -1;
			for (int i = 0; i < size; i++) {
				int w = (m_scene.m_distance[i] >> 1);
				int sx = m_scene.m_dx[i] - w;
				int px = m_scene.m_dx[i] + w;
				int sy = m_scene.m_dy[i] - w;
				int py = m_scene.m_dy[i] + w;
				if (m_posX > sx && m_posX < px && m_posY > sy && m_posY < py) {
					index = i;
					break;
				}
			}
			// Tools.debugPrintln("index="+index);
			boolean flag = false;
			for (int i = 0; i < size; i++) {
				if (m_scene.m_isIn[i] == 1 && i != index) {
					m_scene.m_isIn[i] = 0;
					String txt = "您已经离开了" + m_scene.m_dname[i] + "区域";
					DWGameManager.getInstance().addSystemInfo(
							DWGameManager.SYSTEM_INFO_TYPE_B, txt);
					flag = true;
					break;
				}
			}
			if (index != -1 && !flag) {
				// 进入某值范围，并且当前范围没有进入过
				if (m_scene.m_isIn[index] == 0) {
					m_scene.m_isIn[index] = 1;
					String txt = "您进入了" + m_scene.m_dname[index] + "区域";
					DWGameManager.getInstance().addSystemInfo(
							DWGameManager.SYSTEM_INFO_TYPE_B, txt);
				}
			}
		}
	}

	private void openAutoPathfinding(RoleCombatSkill skill, GameActor target)
	{
		doPath(new PointF(target.m_posX, target.m_posY));
		m_auto_skill = skill;
		m_auto_target = target;
		m_skill_auto = true;
	}

	// ////////////////////////////////////////////////////////
	// //////组队
	// ////////////////////////////////////////////////////////
	public void recvTeamLeaderChange(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("325: 队伍变更指令");
		byte type = dis.readByte(); //
		Tools.debugPrintln("队伍变更类型： " + type);
		long targetID; // 离队队员ID
		Vector teamVector = DWGameManager.getInstance().m_role.m_roleTeam;
		switch (type) {
			case 1: // 新建队伍
				teamVector.removeAllElements();
				DWGameManager.getInstance().m_role.m_teamID = dis.readLong(); // 队伍ID
				DWGameManager.getInstance().m_role.m_leaderID = dis.readLong();// 队长ID
				int memberNum = dis.readInt(); // 队员数量
				Tools.debugPrintln("队员数量" + memberNum);
				for (int i = 0; i < memberNum; i++) {
					Role teamrole = new Role();
					teamrole.m_gameId = dis.readLong(); // 队员ID
					Tools.debugPrintln("队员id" + teamrole.m_gameId);
					teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线
					// 0在线//
					// 1不在线
					Tools.debugPrintln("是否在线" + teamrole.m_online);
					if (teamrole.m_online) {
						teamrole.m_name = dis.readUTF(); // 名字
						teamrole.m_sex = dis.readByte();// 性别
						teamrole.m_grade = dis.readInt(); // 等级

						Tools.debugPrintln("队员名字：" + teamrole.m_name);
						Tools.debugPrintln("等级：" + teamrole.m_grade);
						Tools.debugPrintln("性别：" + teamrole.m_sex);

						// //职业
						teamrole.m_vocation = dis.readByte();
					}
					teamVector.addElement(teamrole);
				}
				break;
			case 2: // 解散队伍
				DWGameManager.getInstance().m_role.m_teamID = 0;
				DWGameManager.getInstance().m_role.m_leaderID = 0;
				teamVector.removeAllElements();
				break;
			case 3: // 上线
				teamVector.removeAllElements();
				DWGameManager.getInstance().m_role.m_teamID = dis.readLong(); // 队伍ID
				DWGameManager.getInstance().m_role.m_leaderID = dis.readLong();// 队长ID
				int memberNum3 = dis.readInt(); // 队员数量
				Tools.debugPrintln("队员数量" + memberNum3);
				for (int i = 0; i < memberNum3; i++) {
					Role teamrole = new Role();
					teamrole.m_gameId = dis.readLong(); // 队员ID
					Tools.debugPrintln("队员id" + teamrole.m_gameId);
					teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线
					// 0在线//
					// 1不在线
					Tools.debugPrintln("是否在线" + teamrole.m_online);
					if (teamrole.m_online) {
						teamrole.m_name = dis.readUTF(); // 名字
						teamrole.m_sex = dis.readByte();// 性别
						teamrole.m_grade = dis.readInt(); // 等级

						Tools.debugPrintln("队员名字：" + teamrole.m_name);
						Tools.debugPrintln("等级：" + teamrole.m_grade);
						Tools.debugPrintln("性别：" + teamrole.m_sex);

						// 职业
						teamrole.m_vocation = dis.readByte();
					}
					teamVector.addElement(teamrole);
				}
				break;
			case 4: // 下线
				targetID = dis.readLong(); // 离线成员ID
				if (teamVector == null) {
					break;
				}
				for (int i = 0, size = teamVector.size(); i < size; i++) {
					Role role = (Role) teamVector.elementAt(i);
					if (role.m_gameId == targetID) {
						role.m_online = false;
					}
				}
				break;
			case 5: // 入队
				teamVector.removeAllElements();
				DWGameManager.getInstance().m_role.m_teamID = dis.readLong(); // 队伍ID
				DWGameManager.getInstance().m_role.m_leaderID = dis.readLong();// 队长ID
				int memberNum2 = dis.readInt(); // 队员数量
				Tools.debugPrintln("队员数量" + memberNum2);
				for (int i = 0; i < memberNum2; i++) {
					Role teamrole = new Role();
					teamrole.m_gameId = dis.readLong(); // 队员ID
					Tools.debugPrintln("队员id" + teamrole.m_gameId);
					teamrole.m_online = ((dis.readByte() == 0) ? true : false);// 是否在线
					// 0在线//
					// 1不在线
					Tools.debugPrintln("是否在线" + teamrole.m_online);
					if (teamrole.m_online) {
						teamrole.m_name = dis.readUTF(); // 名字
						teamrole.m_sex = dis.readByte();// 性别
						teamrole.m_grade = dis.readInt(); // 等级

						Tools.debugPrintln("队员名字：" + teamrole.m_name);
						Tools.debugPrintln("等级：" + teamrole.m_grade);
						Tools.debugPrintln("性别：" + teamrole.m_sex);

						// 职业
						teamrole.m_vocation = dis.readByte();
					}
					teamVector.addElement(teamrole);
				}
				break;
			case 6: // 离队
				targetID = dis.readLong(); // 离队成员ID
				if (targetID == DWGameManager.getInstance().m_role.m_gameId) {
					teamVector.removeAllElements();
					break;
				}
				for (int i = 0; i < teamVector.size(); i++) {
					long roleID = ((Role) teamVector.elementAt(i)).m_gameId;
					if (targetID == roleID) {
						teamVector.removeElementAt(i);
					}
				}
				break;
			case 7: // 队长变更
				DWGameManager.getInstance().m_role.m_leaderID = dis.readLong();
				break;
		}
		if (UIWindows.getMain() != null) {
			UIWindows.getMain().updateTeam();
		}
	}

	/**
	 * 施法计时
	 */
	public void castingTimeTick()
	{
		if (m_castingTimeCounter > 0) {
			m_castingTimeCounter--;
		}
	}

	/**
	 * 打开道具CD
	 * 
	 * @param type
	 * @param index
	 */
	public boolean openItemCD(byte type, int index)
	{
		Cell[] cells = getCells((int) type);
		if (index > -1 && index < cells.length) {
			if (cells[index] != null) {
				Item item = cells[index].m_item;
				if (item != null && item instanceof ItemConsume) {
					ItemConsume consume = (ItemConsume) item;
					String key = String.valueOf(consume.m_cd_type);
					if (m_item_cd.containsKey(key)) {
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_B, "道具使用CD中");
						return false;
					}
					if (consume.m_time_cd > 0) {
						long curTime = System.currentTimeMillis();
						long cdTime = consume.m_time_cd;
						Long[] value = new Long[2];
						value[0] = Long.valueOf(curTime);
						value[1] = Long.valueOf(cdTime);
						m_item_cd.put(key, value);
					}
				}
			}
		}
		return true;
	}

	/** 通过GUID直接找到对象 */
	public Item getItemByGuidForAllColumn(long guid)
	{
		if (guid <= 0) {
			return null;
		}
		Item item = null;
		int type = Cell.TYPE_COLUMN_ROLEBAG;
		
		while (type <= Cell.TYPE_COLUMN_EQUIP) {
			Cell[] cell = getCells(type);
			for (Cell c : cell) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					item = c.m_item;
					type = Cell.TYPE_COLUMN_WAREHOUSE;
					break;
				}
			}
			type++;
		}
		return item;
	}

	/** 通过KEY直接找到对象 */
	public Cell getCellByKeyForRoleBagColumn(String key)
	{
		Cell cell = null;
		Cell[] cells = getCells(Cell.TYPE_COLUMN_ROLEBAG);
		for (Cell c : cells) {
			if (c.m_item != null && c.m_item.m_key.equals(key)) {
				cell = c;
				break;
			}
		}
		return cell;
	}

	/** 通过GUID直接找到背包或者装备栏的对象 */
	public Cell getCellByGuidForRoleBagColumn(long guid)
	{
		Cell cell = null;
		for (int i = 0; i < 2; i++) {
			Cell[] cells = getCells(i);
			for (Cell c : cells) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					cell = c;
				}
			}
		}
		return cell;
	}

	/**
	 * 根据Key获得对应的道具格子
	 * 
	 * @param key
	 * @return
	 */
	public Cell getShortCutItemRide(String guid)
	{
		Cell cell = null;
		if (guid != null && !guid.equals("")) {
			cell = new Cell();
			Item item = new ItemEquipment();
			item.m_guid = Long.parseLong(guid);
			cell.m_item = item;
			item = null;
		}
		return cell;
	}

	/**
	 * 根据Key获得对应的道具格子
	 * 
	 * @param key
	 * @return
	 */
	public Cell getShortCutConsume(String key)
	{
		Cell cell = null;
		if (key != null) {
			cell = getCellByKeyForRoleBagColumn(key);
			if (cell == null) {
				return cell;
			}
			cell = cell.Clone();
			int num = getItemCountManager(Cell.TYPE_COLUMN_ROLEBAG, key);
			cell.m_item.m_num = num;
		}
		return cell;
	}

	/**
	 * 根据id获得对应的技能
	 * 
	 * @param id
	 * @return
	 */
	public RoleCombatSkill getCombatSkill(String id)
	{
		RoleCombatSkill skill = null;
		for (int i = 0; i < m_roleCombatSkill.size(); i++) {
			skill = m_roleCombatSkill.get(i);
			if (skill == null)
				continue;
			if (skill.m_id.equals(id))
				return skill;
		}
		return null;
	}

	// /**
	// * 检测目标周围碰撞
	// *
	// * @param target
	// */
	// private void changeTargetAround(AbstractGameActor target)
	// {
	// if (target == null)
	// return;
	// Background bg = DWGameManager.getInstance().m_scene.m_bg;
	// byte index = 0;
	// if (target.m_posY < m_posY && target.m_posX < m_posX) {// 在右下
	// Tools.debugPrintln("右下!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_RD);
	// }
	// else if (target.m_posX < m_posX) {// 在右上
	// Tools.debugPrintln("右上!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_RU);
	// }
	// else if (target.m_posY < m_posY) {// 在左下
	// Tools.debugPrintln("左下!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_LD);
	// }
	// else {// 在左上
	// Tools.debugPrintln("左上!");
	// index = getMapAroundCollide(bg, target.m_posX, target.m_posY,
	// AROUND_DIRECT_LU);
	// }
	// if (index == -1) {
	// m_posX = target.m_posX;
	// m_posY = target.m_posY;
	// }
	// else {
	// m_posX = target.m_posX + bg.m_tileW * MAP_AROUND_COLLIDE[index][0];
	// m_posY = target.m_posY + bg.m_tileH * MAP_AROUND_COLLIDE[index][1];
	// }
	// Tools.debugPrintln("位移索引 : " + index);
	// }

	// /**
	// * 根据地图得到目标周围无碰撞的索引
	// *
	// * @param bg
	// * @param x
	// * @param y
	// * @param dir
	// * @return
	// */
	// private byte getMapAroundCollide(Background bg, int x, int y, byte dir)
	// {
	// byte[] map = bg.getPhyData();
	// for (byte i = 0, j = dir, k = dir; i < (MAP_AROUND_COLLIDE.length >> 1);
	// i++) {
	// int tile = (y / bg.m_tileH + MAP_AROUND_COLLIDE[j][1])
	// * bg.m_columns
	// + (x / bg.m_tileW + MAP_AROUND_COLLIDE[j][0]);
	// if (tile < map.length && map[tile] != 0) {
	// return j;
	// }
	// j = (byte) (--j < 0 ? MAP_AROUND_COLLIDE.length - 1 : j);
	// k = (byte) (++k >= MAP_AROUND_COLLIDE.length ? 0 : k);
	// tile = (y / bg.m_tileH + MAP_AROUND_COLLIDE[k][1]) * bg.m_columns
	// + (x / bg.m_tileW + MAP_AROUND_COLLIDE[k][0]);
	// if (tile < map.length && map[tile] != 0) {
	// return k;
	// }
	// }
	// return -1;
	// }
	//
	// private byte[][] MAP_AROUND_COLLIDE = { { -1, -1 }, { 0, -1 }, { 1, -1 },
	// { 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -1, 0 } };
	// private final byte AROUND_DIRECT_RD = 4;// 右下
	// private final byte AROUND_DIRECT_RU = 2;// 右上
	// private final byte AROUND_DIRECT_LD = 6;// 左下
	// private final byte AROUND_DIRECT_LU = 0;// 左上

	private final String SKILL_HINT_CLIENT = "";
	private final String SKILL_HINT_DISSATISFY = "释放条件不满足" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_GCD = "公共CD冷却中" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_COOLING = "技能冷却中" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_MANA = "法力不足" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_NO_TARGET = "当前无目标" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_INVALID_TARGET = "无效的当前目标"
			+ SKILL_HINT_CLIENT;
	private final String SKILL_HINT_DEAD_TARGET = "目标已死亡" + SKILL_HINT_CLIENT;
	private final String SKILL_HINT_LIVE_TARGET = "目标未死亡" + SKILL_HINT_CLIENT;

	private void resetAutoPathfinding()
	{
		m_auto_skill = null;
		m_auto_target = null;
		m_skill_auto = false;
		clearPathfinding();
		// stay(m_direct);
	}

	public void breakAutoAttack()
	{
		m_auto_skill = null;
		m_auto_target = null;
		m_skill_auto = false;
		clearAutoAttack();
		Tools.debugPrintln("breakAutoAttack()");
	}

	/**
	 * cooldown
	 */
	public void cooldown()
	{
		if (m_roleCombatSkill != null) {
			RoleCombatSkill skill;
			for (int i = 0; i < m_roleCombatSkill.size(); i++) {
				skill = m_roleCombatSkill.get(i);
				if (skill != null) {
					skill.cooldown();
				}
			}
		}
		logicItemCd();
	}

	public void dealDead()
	{
		if (m_status != ACTOR_STATUS_DEAD)
			return;
		if (!m_enabled)
			return;
		super.dealDead();
		if (m_gameId == m_scene.m_controlledActor.m_gameId) {
			stopCasting();
			stopCastingDescription();
			m_isCasting = false;

			m_scene.setTargetActor(null);

			setAction(ACTION_DEAD * GameActorConstants.DIRECT_NUM + m_direct,
					0, 0, false, false);
		}
		else {
			if (m_flexBuffer.isEmpty() && m_vX == 0 && m_vY == 0) {
				setAction(ACTION_DEAD * GameActorConstants.DIRECT_NUM
						+ m_direct, false, false);
			}
		}
	}

	@Override
	public boolean isDead()
	{
		return m_status == Role.ACTOR_STATUS_DEAD;
	}

	// // 战斗技能相关
	// ////////////////////////////////////////////////////////////

	// ////////////////////////////////////////////////////////////
	// // 角色行为

	/**
	 * 根据data进行相应的动作
	 * 
	 * @param data
	 */
	// public int doAction(Object data)
	// {
	// if (data == null)
	// return DWGameManager.MACRO_STATE_EXCEPTION;
	// long[] info = (long[]) data;
	// int type = (int) info[0];
	// long id = info[1];
	// byte status = (byte) info[2];
	// switch (type) {
	// case ACTION_TYPE_SKILL:
	// Role role = DWGameManager.getInstance().mRole;
	// RoleCombatSkill skill = role.getCombatSkill((short) id);
	// if (status == DWGameManager.MACRO_STATE_READY) {
	// if (role.canUseCombatSkill(skill, role.m_targetActor)) {// 冷却中,播放中,法力不足
	// role.useCombatSkill(skill);
	// }
	// else if (skill == null) {// 技能为空
	// return DWGameManager.MACRO_STATE_EXCEPTION;
	// }
	// else if (role.m_publicCD_skill_counter <= 0) {// 公共CD中
	// setAutoAttack(skill);
	// return DWGameManager.MACRO_STATE_EXCEPTION;
	// }
	// return DWGameManager.MACRO_STATE_GOING;
	// }
	// else if (status == DWGameManager.MACRO_STATE_GOING) {
	// if (role.m_curCombatSkill == null && !role.m_isCasting &&
	// role.m_actionOver && role.m_publicCD_skill <= 0) {
	// role.setAction(Role.ACTION_STAND * Role.DIRECT_NUM + role.m_direct,
	// false);
	// return DWGameManager.MACRO_STATE_FINISH;
	// }
	// setAutoAttack(skill);
	// return DWGameManager.MACRO_STATE_GOING;
	// }
	// case ACTION_TYPE_ITEM:
	// ActorItem item =
	// DWGameManager.getInstance().mRole.getActorItemByKeyID(id);
	// if (item != null) {
	// DWGameManager.getInstance().m_game_message.sendActorItemUse(
	// item.m_layerActorItem, item.m_index);
	// }
	// break;
	// case ACTION_TYPE_FUNCTION:
	// doFunction((int) id);
	// break;
	// }
	// return DWGameManager.MACRO_STATE_FINISH;
	// }

	/**
	 * 设置自动攻击, 先停留10帧
	 */
	public void initAutoAttack(RoleCombatSkill skill)
	{
		m_buffer_skill = skill;
	}

	/**
	 * 设置下一次技能, 按键缓存
	 * 
	 * @param skill
	 */
	// private void setAutoAttack(RoleCombatSkill skill)
	// {
	// if (m_status != ACTOR_STATUS_ROLE_DEAD)
	// m_buffer_skill = skill;
	// }

	/**
	 * 清除自动攻击
	 */
	public void clearAutoAttack()
	{
		m_buffer_skill = null;
	}

	public boolean m_isride = false; // 人物坐骑状态 false 代表没有骑上坐骑
	public static final byte RIDE_DOWN = 1; // 下坐骑
	public static final byte RIDE_UP = 2; // 上坐骑

	/**
	 * 一键使用坐骑
	 * 
	 * @param isRide
	 */
	public void oneKeyUseRide(ItemEquipment rideItem2)
	{
		ItemEquipment rideItem = rideItem2;
		if (rideItem != null) {
			if (m_isride) {
				Tools.debugPrintln("下坐骑");
				DWGameManager.getInstance().getSendMessage()
						.sendRideStart(RIDE_DOWN, rideItem.m_guid);
				stay(m_direct);
			}
			else {
				Tools.debugPrintln("上坐骑");
				DWGameManager.getInstance().getSendMessage()
						.sendRideStart(RIDE_UP, rideItem.m_guid);
				int resType = DWSerializableFactory.RESOURCE_TYPE_ANIM;
				Role rideRole = DWGameManager.getInstance().m_role;
				StringBuffer resUrl = new StringBuffer()
						.append(DWSerializableFactory.DIR_ANIM)
						.append(rideItem.m_anim_url[0])
						.append(DWSerializableFactory.EXTENSION_ANIM);
				int resVersion = 1;
				ResHead head = new ResHead(resType, resUrl.toString(),
						resVersion);
				rideRole.m_refsResHead[Role.ANIM_RIDE] = head;
				if (rideRole.m_anims[Role.ANIM_RIDE] == null
						|| !rideRole.m_anims[Role.ANIM_RIDE].m_resHead
								.equals(rideRole.m_anims[Role.ANIM_RIDE].m_refsResHead[Role.ANIM_RIDE])) {
					rideRole.m_anims[Role.ANIM_RIDE] = (Animation) (ResourceManager
							.getInstance().loadResource(
							DWGameManager.getInstance().m_resourceDynamic,
							rideRole.m_refsResHead[Role.ANIM_RIDE]));
				}
				rideRole.m_isride = true;
				if (rideRole.m_ride != null) {
					rideRole.m_ride.dispose();
					rideRole.m_ride = null;
				}
				rideRole.m_ride = new Actor(rideRole.m_anims[Role.ANIM_RIDE]);
				stay(m_direct);
			}
		}
	}

	/**
	 * 是否开始上坐骑
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvRideIsStart(DataInputStream dis) throws IOException
	{
		byte type = dis.readByte(); // 1 下坐骑 2上坐骑
		String msg = dis.readUTF();// 提示信息
		Tools.debugPrintln(type + "   :1 下坐骑 2上坐骑 :" + msg);
		if (msg != null && !msg.equals("")) {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_C, msg);
		}
	}

	// /////////////////////////////////////////////////////
	// 角色复活指令
	// /////////////////////////////////////////////////////
	private String[] m_dead_popups = null;//
	private int[] m_dead_instruct = null;

	/**
	 * 死亡后弹出窗口
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvDeadPopups(DataInputStream dis) throws IOException
	{
		int size = dis.readInt();
		m_dead_popups = null;
		m_dead_popups = new String[size];
		m_dead_instruct = new int[size];
		for (int i = 0; i < size; i++) {
			m_dead_popups[i] = dis.readUTF();
			m_dead_instruct[i] = dis.readInt();
			Tools.debugPrintln("m_dead_popups[" + i + "] = " + m_dead_popups[i]);
			Tools.debugPrintln("m_dead_instruct[" + i + "] = "
					+ m_dead_instruct[i]);
		}
		if (size > 0) {
			showDeadDialogMenu();
		}
	}

	/**
	 * 显示一个死亡后的弹出窗口
	 */
	public void showDeadDialogMenu()
	{
		// if (m_status == ACTOR_STATUS_ROLE_DEAD && dm == null && m_dead_popups
		// != null && m_dead_popups.length > 0) {
		// dm = (UIDialogMenu)
		// UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU);
		// dm.setContents("请选择", "你已经死亡", m_dead_popups);
		// dm.addListener(new UIListener() {
		// public void actionPerformed()
		// {
		// if
		// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
		// || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
		// if (m_dead_instruct[dm.getCurrentIndex()] > 0) {
		// DWGameManager.getInstance().m_game_message.sendReviveFunction(m_dead_instruct[dm.getCurrentIndex()]);
		// }
		// else {
		// UIManager.getInstance().removeWindow(dm);
		// dm = null;
		// }
		// }
		// }
		// });
		// }
	}

	// public UIDialogMenu dm = null;
	// public UIMessageBox mb = null;

	/**
	 * 他人复活确认
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvReviveConfirmation(DataInputStream dis) throws IOException
	{
		// String msg = dis.readUTF();
		// if (msg != null) {
		// mb = (UIMessageBox)
		// UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MESSAGEBOX);
		// mb.setCentre();
		// mb.setMessage(msg);
		// mb.addListener(new UIListener() {
		// public void actionPerformed()
		// {
		// if
		// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
		// || AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
		// DWGameManager.getInstance().m_game_message.sendReviveAgree();
		// }
		// else if
		// (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT))
		// {
		// UIManager.getInstance().removeWindow(mb);
		// }
		// }
		// });
		// }
	}

	/**
	 * 同意他人复活
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvReviveAgree(DataInputStream dis) throws IOException
	{
		short status = dis.readShort();
		String msg = dis.readUTF();
		if (status == 1) {
			DWGameManager.getInstance().m_role.m_hp = dis.readInt();
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateMyHead();
			}
			// if (mb != null) {
			// UIManager.getInstance().removeWindow(mb);
			// mb = null;
			// }
			// if (dm != null) {
			// UIManager.getInstance().removeWindow(dm);
			// dm = null;
			// }
		}
		else {
			Tools.debugPrintln("同意他人复活失败!" + msg);
		}
	}

	/**
	 * 原地复活
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvRevivePos(DataInputStream dis) throws IOException
	{
		short status = dis.readShort();
		String msg = dis.readUTF();
		if (status == 1) {
			DWGameManager.getInstance().m_role.m_hp = dis.readInt();
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateMyHead();
			}
			// if (dm != null) {
			// UIManager.getInstance().removeWindow(dm);
			// dm = null;
			// }
		}
		else {
			Tools.debugPrintln("原地复活失败!" + msg);
		}
	}

	/**
	 * 更新角色职业
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvUpdateJob(DataInputStream dis) throws IOException
	{
		byte job = dis.readByte();
		Tools.debugPrintln("更新玩家职业 : " + job);
		m_vocation = job;
	}

	/**
	 * 更新剑客最大剑气
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvUpdateMaxJQ(DataInputStream dis) throws IOException
	{
		byte maxJQ = dis.readByte();
		Tools.debugPrintln("更新剑客最大剑气" + maxJQ);
		m_mpMax = maxJQ;
	}

	Npc m_npc;//小任务提示区
	public boolean m_taskOpen;//任务寻路打怪标示 

	public void sceneAutoPathfinding()
	{
		if (m_pathfinding_start && !m_pathfinding_pause) {
			// DWGameManager gm = DWGameManager.getInstance();
			if (m_pathfinding_label >= m_pathfinding_point.size()) {// 已经到达最后点
				clearPathfinding();
				stay(m_direct);
				findGateway();
			}
			else {
				Background background = m_scene.m_bg;
				PointF info = (PointF) m_pathfinding_point
						.get(m_pathfinding_label);
				int x = (int) info.x;
				int y = (int) info.y;
				if (m_pathfinding_paths == null) {// 路径为空
					int start = BinHeapAStar.convertXYtoPoint(
							DWGameManager.getInstance().m_role.m_posX,
							DWGameManager.getInstance().m_role.m_posY,
							background.m_tileW, background.m_tileH,
							background.m_columns);
					int end = BinHeapAStar.convertXYtoPoint(x, y,
							background.m_tileW, background.m_tileH,
							background.m_columns);
					m_pathfinding_paths = BinHeapAStar.findPath(
							background.getPhyData(), background.m_columns,
							background.m_rows, start, end);
					Tools.debugPrintln("第" + m_pathfinding_label + "次寻路 : " + x
							+ " : " + y);
					if (m_pathfinding_paths == null) {
						Tools.debugPrintln("无法到达当前点!"
								+ background.m_resHead.m_url);
						clearPathfinding();
						resetAutoPathfinding();
					}
					else {
						Tools.debugPrintln("寻路长度 : " + m_pathfinding_paths);
					}
				}
				else {
					if (Math.abs(m_posX - x) < background.m_tileW
							&& Math.abs(m_posY - y) < background.m_tileH) {
						if (m_pathfinding_way == 0) {
							clearPathfinding();
							stay(m_direct);
							findGateway();
						}
						else if (m_pathfinding_way == 1) {
							if (m_pathfinding_label == m_pathfinding_point
									.size() - 1) {// 到达最后的点
								Npc npc = m_scene.getNPCByID(m_pathfinding_id);
								m_npc = npc;
								Tools.debugPrintln("任务寻路结束 搜索ID : "
										+ m_pathfinding_id + " : " + npc);
								if (npc != null) {
									((Scene) m_scene).setTargetActor(npc);
									if (npc.m_type == GameActorConstants.ACTOR_TYPE_NPC
											|| npc.m_type == GameActorConstants.ACTOR_TYPE_GATHERING) {
										DWGameManager.getInstance()
												.getSendMessage()
												.sendNPCList(npc.m_gameId);
									}
									else if (npc.m_type == GameActorConstants.ACTOR_TYPE_MONSTER) {
										UIHook.s_autoHook = true;
										m_taskOpen = true;
										UIWindows.getInstance().m_hook.setPosXY(m_posX, m_posY);
									}
									stay(m_direct);
								}
								clearPathfinding();
							}
							else {// 没到达最后的点,需要等玩家点击传送
								pausePathfinding();
								findGateway();
							}
						}
					}
					else {// 自动走路中
						if (m_pathfinding_index >= m_pathfinding_paths.length) {
							Tools.debugPrintln("自动走路中越界 : "
									+ m_pathfinding_paths.length + " : "
									+ m_pathfinding_index);
							clearPathfinding();
							stay(m_direct);
						}
						else {
							int targetX = ((m_pathfinding_paths[m_pathfinding_index] % background.m_columns) * background.m_tileW)
									+ (background.m_tileW >> 1);
							int targetY = ((m_pathfinding_paths[m_pathfinding_index] / background.m_columns) * background.m_tileH)
									+ (background.m_tileH >> 1);
							int dValueX = targetX - m_posX;
							int dValueY = targetY - m_posY;

							if (Math.abs(dValueX) <= 1
									&& Math.abs(dValueY) <= 1) {
								m_vX = 0;
								m_vY = 0;
								m_pathfinding_index++;
								return;
							}

							float hypotenuse = (float) Math.sqrt(dValueX
									* dValueX + dValueY * dValueY);
							float vx = dValueX * m_velocity / hypotenuse;
							float vy = dValueY * m_velocity / hypotenuse;
							if (Math.abs(dValueX) <= Math.abs(vx)) {
								vx = dValueX;
							}
							if (Math.abs(dValueY) <= Math.abs(vy)) {
								vy = dValueY;
							}
							move(vx, vy, Math.min(m_velocity, hypotenuse));
							if (Math.abs(dValueX) <= Math.abs(vx)
									+ (background.m_tileW >> 2)
									&& Math.abs(dValueY) <= Math.abs(vy)
											+ (background.m_tileW >> 2)) {
								m_pathfinding_index++;
							}
						}
					}
				}
			}
		}
	}

	/**
	 * 寻找传送门
	 */
	public void findGateway()
	{
		Hashtable<Long, GameActor> actorsHT = m_scene.m_dynamicActors;
		Object[] actors = actorsHT.values().toArray();
		for (Object o : actors) {
			final GameActor actor = (GameActor) o;
			if (actor != null && actor instanceof Npc) {
				if (actor.m_type == GameActorConstants.ACTOR_TYPE_GATE
						&& actor.collide((m_scene).m_controlledActor, true)) {
					m_is_autopath = true;
					// 设置角色站立
					stay(m_direct);
					final DWMessageBox messageBox = new DWMessageBox("", "确认去"
							+ actor.m_name + "?");
					messageBox.addListener(new DWListener() {
						public void OnDoubleClick()
						{
						}

						public void OnClick()
						{
							if (DWMessageBox.SOFTKEY_OK == messageBox
									.getResult()) {
								DWGameManager.getInstance().getSendMessage()
										.sendChange(actor.m_gameId);
								DWControlsManager.getInstance().removeControl(
										messageBox);
							}
							else if (DWMessageBox.SOFTKEY_BACK == messageBox
									.getResult()) {
								DWControlsManager.getInstance().removeControl(
										messageBox);
							}

						}
					});
					DWControlsManager.getInstance().addControl(messageBox);
				}
			}
		}
	}

	/**
	 * 清理寻路数据
	 */
	public void clearPathfinding()
	{
		m_pathfinding_point = null;// 寻路终点集合
		m_pathfinding_label = 0;// 寻路终点索引
		m_pathfinding_pause = false;// 是否暂停
		m_pathfinding_start = false;// 是否在寻路
		m_pathfinding_paths = null;// 寻路的路径集合
		m_pathfinding_index = 1;
		m_pathfinding_id = 0;// 寻路的目标ID
	}

	public void pausePathfinding()
	{
		m_pathfinding_label++;
		m_pathfinding_index = 0;
		m_pathfinding_paths = null;
		m_pathfinding_pause = true;
		stay(m_direct);
	}

	// // 角色行为
	// ////////////////////////////////////////////////////////////

	/**
	 * 动作列表
	 */
	public static final int ACTION_STAND = 0;
	public static final int ACTION_MOVE = 1;
	public static final int ACTION_STAND_RIDE = 2;
	public static final int ACTION_MOVE_RIDE = 3;
	public static final int ACTION_PICK = 4;
	public static final int ACTION_DEAD = 5;
	public static final int ACTION_ATTACK1 = 6;
	public static final int ACTION_ATTACK2 = 7;
	public static final int ACTION_ATTACK1_RIDE = 8;
	public static final int ACTION_ATTACK2_RIDE = 9;
	public static final int ACTION_HEAD = 10;

	// 状态
	public static final int ACTOR_STATUS_FREE = 0;// 玩家自由状态
	public static final int ACTOR_STATUS_DEAD = 32;// 玩家死亡状态

	/**
	 * 角色的按键移动 人物移动 后面要改
	 */
	public void doPath(PointF point)
	{
		clearPathfinding();
		m_pathfinding_point = new Vector();
		m_pathfinding_point.add(point);
		m_pathfinding_way = 0;
		m_pathfinding_start = true;
		m_pathfinding_pause = false;
	}

	/**
	 * 角色移动npc 人物移动 后面要改
	 */
	public void doPath(PointF[] points)
	{
		// clearPathfinding();
		m_pathfinding_point = new Vector();
		if (points != null) {
			for (int i = 0; i < points.length; i++) {
				PointF point = points[i];
				m_pathfinding_point.add(point);
			}
		}
		m_pathfinding_way = 1;
		m_pathfinding_start = true;
		m_pathfinding_pause = false;
	}

	/**
	 * 道具计数集合 不含装备类型 String：m_key Integer: nums
	 */
	public Hashtable<String, Integer> m_bag_itemscount;// 背包计数
	public Hashtable<String, Integer> m_warehouse_itemscount;// 仓库计数

	/** 角色获得道具的临时缓存 用于做动画显示动态进入背包 */
	public CopyOnWriteArrayList<PickItem> m_pick_items = new CopyOnWriteArrayList<PickItem>();

	/**
	 * @exception 加入得到的新道具进入列表
	 * @param Item
	 * 道具
	 * */
	public void addToPickItem(Item object)
	{
		if (object != null) {
			Tools.debugPrintln("object name=" + object.m_name);
		}
		else {
			Tools.debugPrintln("object = NULL");
		}
		if (object != null) {
			PickItem pick = new PickItem();
			pick.m_bitmap = object.m_icon;
			m_pick_items.add(pick);
			pick = null;
		}
	}

	public static final int NUM_COLUMN_EQUIPMENT = 12;// 装备栏数目
	public static final int NUM_COLUNM_BAG = 108;// 背包栏数目

	public static int[] COLUMN_MAX_SIZE = new int[4];
	/**
	 * 装备栏
	 */
	public Cell[] m_column_equip;

	/**
	 * 背包栏
	 */
	public Cell[] m_column_bag;

	/**
	 * 仓库栏
	 * */
	public Cell[] m_column_warehouse;

	/***
	 * 摆摊栏
	 */
	public Cell[] m_column_shop;

	/**
	 * 天命相关
	 */
	public int tianmingweiNum = 7;
	public Tianming[] m_tianming_minggewei;// 天命装备位背包
	public Tianming[] m_tianming_bag;// 天命背包
	public int[] m_tianming_shengJBMoney = new int[5]; // 拜神费
	public int m_tianming_nextNeedLevel; // 开启新天命位需要的级别
	public Tianming[] xianshiBag;
	/**
	 * 宠物
	 */
	public byte petCellMin;// 开启格子数
	public byte petCellMax; // 格子总数

	/**
	 * @exception 刷新道具计数
	 * @param type
	 * 格子类型
	 * @param item
	 * 道具
	 * @param boolean 是否需要更新快捷栏
	 * */
	public void updataItemCount(byte type, Item item, boolean isShortCut)
	{
		if (item == null) {
			return;
		}
		if (item.m_type == ItemConstants.道具类型_消耗
				|| item.m_type == ItemConstants.道具类型_宝石
				|| item.m_type == ItemConstants.道具类型_其他) {
			int num = item.m_num;
			boolean flag = false;
			String key_url;
			switch (type) {
				case Cell.TYPE_COLUMN_ROLEBAG:
					key_url = item.m_key;
					flag = m_bag_itemscount.containsKey(key_url);
					if (flag) {
						num += m_bag_itemscount.get(key_url).intValue();
					}
					if (num > 0) {
						m_bag_itemscount.put(key_url, num);
					}
					else {
						m_bag_itemscount.remove(key_url);
						if (isShortCut) {
							if (m_shortcut != null) {
								if (m_shortcut[SHORTCUT_RIDE] != null
										&& m_shortcut[SHORTCUT_RIDE].equals(String
												.valueOf(item.m_guid))) {
									setShortcut(null, SHORTCUT_RIDE);
								}
								else if (m_shortcut[SHORTCUT_CONSUME] != null
										&& m_shortcut[SHORTCUT_CONSUME]
												.equals(key_url)) {
									setShortcut(null, SHORTCUT_CONSUME);
								}
							}
						}
					}
					if (isShortCut) {
						updataShortcutBar(key_url);
					}
					break;
				case Cell.TYPE_COLUMN_WAREHOUSE:
					key_url = item.m_key;
					flag = m_warehouse_itemscount.containsKey(key_url);
					if (flag) {
						num += m_warehouse_itemscount.get(key_url).intValue();
					}
					if (num > 0) {
						m_warehouse_itemscount.put(key_url, num);
					}
					else {
						m_warehouse_itemscount.remove(key_url);
					}
					break;
				default:
					break;
			}
		}
	}

	/** 更新血瓶快捷栏 */
	public void updataShortcutBar(String key)
	{
		UIBag win = UIWindows.getInstance().m_bag;
		Cell cell = null;
		int num = 0;
		if (win != null && win.m_shortcut_consume != null
				&& win.m_shortcut_consume.m_data != null
				&& win.m_shortcut_consume.m_data instanceof Cell) {
			num = getItemCountManager(Cell.TYPE_COLUMN_ROLEBAG, key);
			cell = (Cell) win.m_shortcut_consume.m_data;
			if (cell.m_item != null && cell.m_item.m_key.equals(key)) {
				if (num <= 0) {
					win.m_shortcut_consume.m_data = null;
				}
				else {
					cell.m_item.m_num = num;
				}
			}
			else {
				return;
			}
		}
		else {
			return;
		}
		UIMain main = UIWindows.getInstance().m_main;
		if (main != null && main.m_grid_dizi[3] != null
				&& main.m_grid_dizi[3].m_data != null
				&& main.m_grid_dizi[3].m_data instanceof Cell) {
			if (main.m_main_roleskill[4] != null
					&& main.m_main_roleskill[4] instanceof Cell) {
				if (num <= 0) {
					main.m_main_roleskill[4] = null;
					main.m_grid_dizi[3].m_data = null;
				}
				else {
					cell = (Cell) main.m_main_roleskill[4];
					if (cell.m_item != null) {
						cell.m_item.m_num = num;
					}
					main.m_grid_dizi[3].m_data = cell;
				}
			}
		}

	}

	public int m_bag_unitPrice = 10;
	public long m_warehouse_unitPrice = 200000;

	/**
	 * 接收创建栏命令
	 * */
	public void recvColumnCommand(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_背包);
		byte type = dis.readByte();// 创建栏的类型
		Tools.debugPrintln("recvColumnCommand type=" + type);
		short maxColumnNum = dis.readShort();// 栏的最大格子数
		short nowColumnNum = dis.readShort();// 栏的实际大小
		Tools.debugPrintln("maxColumnNum=" + maxColumnNum + ";nowColumnNum="
				+ nowColumnNum);
		COLUMN_MAX_SIZE[type] = maxColumnNum;
		boolean isShortCut = true;
		if (type == Cell.TYPE_COLUMN_ROLEBAG) {// 初始化映射背包子栏数据
			if (m_bag_itemscount == null) {
				m_bag_itemscount = new Hashtable<String, Integer>();
			}
			else {
				m_bag_itemscount.clear();
				isShortCut = false;
			}

		}
		else if (type == Cell.TYPE_COLUMN_WAREHOUSE) {
			if (m_warehouse_itemscount == null) {
				m_warehouse_itemscount = new Hashtable<String, Integer>();
			}
			else {
				m_warehouse_itemscount.clear();
			}
		}
		Cell[] cell = new Cell[nowColumnNum];
		for (int i = 0; i < nowColumnNum; i++) {
			cell[i] = new Cell(type, i);
		}
		short item_num = dis.readShort();// 道具数量
		Tools.debugPrintln("item_num=" + item_num);
		for (int i = 0; i < item_num; i++) {
			int index = dis.readShort();// 索引
			Item item = Item.recvItemFormServer(dis);
			updataItemCount(type, item, isShortCut);// 刷新道具数量计数
			Tools.debugPrintln("index=" + index + ";item name=" + item.m_name);
			cell[index].setCell(item, type, index);
			item = null;
		}
		switch (type) {
			case Cell.TYPE_COLUMN_EQUIP:
				m_column_equip = null;
				m_column_equip = cell;
				break;
			case Cell.TYPE_COLUMN_ROLEBAG:
				m_column_bag = null;
				m_column_bag = cell;
				reflashColumnByUI();
				break;
			case Cell.TYPE_COLUMN_WAREHOUSE:
				m_column_warehouse = null;
				m_column_warehouse = cell;
				reflashColumnByWAREHOUSE();
				break;
		}
		cell = null;

		long price = dis.readLong();
		Tools.debugPrintln("背包价格：" + price);

		if (price > 0) {
			if (type == Cell.TYPE_COLUMN_ROLEBAG) {
				// 如果是角色背包读取开启背包格子单价
				m_bag_unitPrice = (int) price;
			}
			else if (type == Cell.TYPE_COLUMN_WAREHOUSE) {
				m_warehouse_unitPrice = price;
			}
		}

	}

	/**
	 * 接收交换格子信息
	 * */
	public void recvExchangeCellCommand(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_背包);
		byte state = dis.readByte();// 状态 0失败 1成功
		if (state == 0) {
			return;
		}
		byte start_type = dis.readByte();
		int start_index = dis.readShort();
		byte target_type = dis.readByte();
		int target_index = dis.readShort();
		Cell startCell = getCells(start_type)[start_index];
		Cell targetCell = getCells(target_type)[target_index];
		if (startCell.m_item != null) {
			Tools.debugPrintln("操作起始格子道具：" + startCell.m_item.m_name);
		}
		if (targetCell.m_item != null) {
			Tools.debugPrintln("操作目标格子道具：" + targetCell.m_item.m_name);
		}
		Item item = targetCell.m_item;
		targetCell.m_item = startCell.m_item;
		startCell.m_item = item;
		if (start_type == Cell.TYPE_COLUMN_ROLEBAG
				|| target_type == Cell.TYPE_COLUMN_ROLEBAG) {
			reflashColumnByUI();
		}
		if (start_type == Cell.TYPE_COLUMN_EQUIP
				|| target_type == Cell.TYPE_COLUMN_EQUIP) {
			reflashColumnByEQUIP();
		}
		if (start_type == Cell.TYPE_COLUMN_WAREHOUSE
				|| target_type == Cell.TYPE_COLUMN_WAREHOUSE) {
			reflashColumnByWAREHOUSE();
		}
		if (item == null) {
			Tools.debugPrintln("目标格子道具为空");
		}
	}

	/**
	 * 接收删除道具信息
	 * */
	public void recvChangeCellCommand(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_背包);
		byte state = dis.readByte();// 状态 0失败 1成功
		if (state == 0) {
			Tools.debugPrintln("改变格子道具数量失败");
			return;
		}
		byte size = dis.readByte();
		boolean flag = false;
		for (int i = 0; i < size; i++) {
			byte type = dis.readByte();// 栏类型
			int index = dis.readShort();// 栏索引
			int num = dis.readShort();// 变化量
			Cell cell = getCells(type)[index];
			if (cell != null && cell.m_item != null) {
				cell.m_item.m_num += num;
				Item item = cell.m_item.Clone();
				item.m_num = num;
				updataItemCount(type, item, true);
				if (num > 0) {
					addToPickItem(item);
				}
				item = null;
				if (cell.m_item.m_num < 1) {
					cell.m_item = null;
				}
			}
			if (type == Cell.TYPE_COLUMN_ROLEBAG) {
				flag = true;
			}
		}
		if (flag) {
			reflashColumnByUI();
		}
	}

	public void reflashColumnByUI()
	{
		UIBag bag = UIWindows.getInstance().m_bag;
		if (bag != null) {
			bag.updateWindow(m_column_bag, Cell.TYPE_COLUMN_ROLEBAG);
		}

		UIWarehouse house = UIWindows.getInstance().m_warehouse;
		if (house != null) {
			house.updateWindow(Cell.TYPE_COLUMN_ROLEBAG);
		}
	}

	public void reflashColumnByEQUIP()
	{
		UIBag bag = UIWindows.getInstance().m_bag;
		if (bag != null) {
			bag.updateWindow(m_column_equip, Cell.TYPE_COLUMN_EQUIP);
		}
	}

	public void reflashColumnByWAREHOUSE()
	{
		UIWarehouse house = UIWindows.getInstance().m_warehouse;
		if (house != null) {
			house.updateWindow(Cell.TYPE_COLUMN_WAREHOUSE);
		}
	}

	/**
	 * 接收装备属性变化
	 * */
	public void recvChangeEquipInfosCommand(DataInputStream dis)
			throws IOException
	{
		long guid = dis.readLong();
		byte size = dis.readByte();
		int type = Cell.TYPE_COLUMN_ROLEBAG;
		while (type <= Cell.TYPE_COLUMN_EQUIP) {
			Cell[] cell = getCells(type);
			for (Cell c : cell) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					ItemEquipment item = (ItemEquipment) c.m_item;
					item.m_attrValue = new int[size];
					item.m_attrAddValue = new int[size];
					item.m_attrAddValus_forge = new int[size];
					for (int i = 0; i < size; i++) {
						item.m_attrValue[i] = dis.readInt();
						item.m_attrAddValue[i] = dis.readInt();
						item.m_attrAddValus_forge[i] = dis.readInt();
					}
					item.m_gs = dis.readInt();
					type = Cell.TYPE_COLUMN_WAREHOUSE;
					break;
				}
			}
			type++;
		}
	}

	/**
	 * 接收装备强化变化
	 * */
	public void recvChangeEquipStrengthenCommand(DataInputStream dis)
			throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_背包);
		long guid = dis.readLong();
		int type = Cell.TYPE_COLUMN_ROLEBAG;
		while (type <= Cell.TYPE_COLUMN_EQUIP) {
			Cell[] cell = getCells(type);
			for (Cell c : cell) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					ItemEquipment item = (ItemEquipment) c.m_item;
					item.m_strengthenLevel = dis.readShort();
					item.m_maxStrengthenLevel = dis.readShort();
					item.m_nowStrengthenSpiritNeedAmount = dis.readShort();
					type = Cell.TYPE_COLUMN_WAREHOUSE;
					break;
				}
			}
			type++;
		}
	}

	/**
	 * 接收装备镶嵌变化
	 * */
	public void recvChangeEquipSetCommand(DataInputStream dis)
			throws IOException
	{
		long guid = dis.readLong();
		int type = Cell.TYPE_COLUMN_ROLEBAG;
		while (type <= Cell.TYPE_COLUMN_EQUIP) {
			Cell[] cell = getCells(type);
			for (Cell c : cell) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					ItemEquipment equip = (ItemEquipment) c.m_item;
					byte equipGsize = dis.readByte();
					// Tools.debugPrintln("刷新宝石的装备："+equip.m_name+";宝石孔数："+equipGsize);
					equip.m_equipGemsSize = equipGsize;
					if (equipGsize > 0) {
						equip.m_hasGem = new byte[equipGsize];
						equip.m_iconidGem = new short[equipGsize];
						equip.m_nameGem = new String[equipGsize];
						equip.m_GemData = new String[equipGsize];
						equip.m_gemIcon = new Bitmap[equipGsize];
						equip.m_gemSamllIcon = new Bitmap[equipGsize];
						for (int i = 0; i < equipGsize; i++) {
							byte hasGem = dis.readByte();
							equip.m_hasGem[i] = hasGem;
							// Tools.debugPrintln("i="+i+";hasGem="+hasGem);
							if (hasGem == ItemConstants.含有宝石_是) {
								equip.m_iconidGem[i] = dis.readShort();
								equip.m_nameGem[i] = dis.readUTF();
								equip.m_GemData[i] = equip.getGemDatas(i);
								equip.m_gemIcon[i] = IconManger.getInstance()
										.getIcon(equip.m_iconidGem[i]);
							}
							else {
								equip.m_GemData[i] = equip.getGemDatas(-1);
							}
							equip.m_gemSamllIcon[i] = IconManger.getInstance()
									.getEquipGemIcon(i, hasGem);
						}
					}
					type = Cell.TYPE_COLUMN_WAREHOUSE;
					break;
				}
			}
			type++;
		}
	}

	/**
	 * 接收装备绑定变化
	 * */
	public void recvChangeEquipBindingCommand(DataInputStream dis)
			throws IOException
	{
		long guid = dis.readLong();
		int type = Cell.TYPE_COLUMN_ROLEBAG;
		while (type <= Cell.TYPE_COLUMN_EQUIP) {
			Cell[] cell = getCells(type);
			for (Cell c : cell) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					ItemEquipment item = (ItemEquipment) c.m_item;
					item.m_bindingState = dis.readByte();
					type = Cell.TYPE_COLUMN_WAREHOUSE;
					break;
				}
			}
			type++;
		}
	}

	/**
	 * 接收装备耐久变化
	 * */
	public void recvChangeEquipDurableCommand(DataInputStream dis)
			throws IOException
	{
		long guid = dis.readLong();
		int type = Cell.TYPE_COLUMN_ROLEBAG;
		while (type <= Cell.TYPE_COLUMN_EQUIP) {
			Cell[] cell = getCells(type);
			for (Cell c : cell) {
				if (c.m_item != null && c.m_item.m_guid == guid) {
					ItemEquipment item = (ItemEquipment) c.m_item;
					item.m_nowDurable = dis.readShort();
					UIFixWindow.setItemFix(item);
					UIWindows.getInstance().m_fix.setDurableMessage();
					type = Cell.TYPE_COLUMN_WAREHOUSE;
					break;
				}
			}
			type++;
		}
	}

	/**
	 * 接收添加道具信息
	 * */
	public void recvAddItemCommand(DataInputStream dis) throws IOException
	{
		int num = dis.readShort();// 道具数量
		boolean flag = false;
		for (int i = 0; i < num; i++) {
			byte type = dis.readByte();// 背包栏类型
			Cell[] cell = getCells(type);
			int index = dis.readShort();
			Item item = Item.recvItemFormServer(dis);
			updataItemCount(type, item, true);
			addToPickItem(item);
			cell[index].m_item = item;
			Tools.debugPrintln("recvAddItemCommand type=" + type
					+ ";item.name=" + cell[index].m_item.m_name);
			item = null;
			if (type == Cell.TYPE_COLUMN_ROLEBAG) {
				flag = true;
			}
		}		if (flag) {
			reflashColumnByUI();
		}
	}

	/**
	 * 接收扩充背包格子
	 * */
	public void recvChangeColumnCellNumbers(DataInputStream dis)
			throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_背包);
		byte type = dis.readByte();// 背包栏类型
		int num = dis.readShort();// 背包扩充后的有效格子
		Cell[] cell = new Cell[num];
		Cell[] old_cell = getCells(type);
		int old_num = old_cell.length;
		if (old_num <= num) {
			for (int i = 0; i < num; i++) {
				if (i < old_num) {
					cell[i] = old_cell[i];
				}
				else {
					cell[i] = new Cell(null, type, i);
				}
			}
			switch (type) {
				case Cell.TYPE_COLUMN_EQUIP:
					m_column_equip = cell;
					break;
				case Cell.TYPE_COLUMN_ROLEBAG:
					m_column_bag = cell;
					reflashColumnByUI();
					break;
				case Cell.TYPE_COLUMN_WAREHOUSE:
					m_column_warehouse = cell;
					reflashColumnByWAREHOUSE();
					break;
			}
		}
	}

	/**
	 * 获取某道具的总数
	 * */
	public int getItemCountManager(byte type, String key)
	{
		int num = 0;
		boolean flag = false;
		switch (type) {
			case Cell.TYPE_COLUMN_ROLEBAG:
				flag = m_bag_itemscount.containsKey(key);
				if (flag) {
					num = m_bag_itemscount.get(key).intValue();
				}
				break;
			case Cell.TYPE_COLUMN_WAREHOUSE:
				flag = m_warehouse_itemscount.containsKey(key);
				if (flag) {
					num = m_warehouse_itemscount.get(key).intValue();
				}
				break;
			default:
				break;
		}
		return num;
	}

	/**
	 * 获得相应的背包
	 * 
	 * @param int 物品栏类型
	 * @return
	 */
	public Cell[] getCells(int columnType)
	{
		switch (columnType) {
			case Cell.TYPE_COLUMN_ROLEBAG:// 角色背包栏
				return m_column_bag;
			case Cell.TYPE_COLUMN_EQUIP:// 装备栏
				return m_column_equip;
			case Cell.TYPE_COLUMN_WAREHOUSE:// 仓库栏
				return m_column_warehouse;
		}
		throw new IllegalArgumentException("无此类型 " + columnType);
	}

	/**
	 * 创建角色邮件
	 * */
	public void recvRequestRoleMails(DataInputStream dis) throws IOException
	{
		if (m_recvMails == null) {
			m_recvMails = new CopyOnWriteArrayList<MailItem>();
		}
		else {
			m_recvMails.clear();
		}
		short size = dis.readShort();// 邮件总数
		Tools.debugPrintln("角色身上的邮件长度=" + size);
		for (int i = 0; i < size; i++) {
			MailItem mail = UIMail.recvMail(dis);
			if (mail != null) {
//				 Tools.debugPrintln("i=" + i + ";mail.title=" + mail.m_title +
//				 ";mail.state=" + mail.m_state);
				m_recvMails.add(mail);
			}
		}
	}

	/**
	 * 获得精力值信息
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvActorVim(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().m_role.m_jinglizhi_zonggong = dis.readInt(); // 总精力值
		DWGameManager.getInstance().m_role.m_jinglizhi_shengyu = dis.readInt(); // 剩余精力值
		Tools.debugPrintln("剩余精力值: "
				+ DWGameManager.getInstance().m_role.m_jinglizhi_zonggong);
		Tools.debugPrintln("剩余精力值: "
				+ DWGameManager.getInstance().m_role.m_jinglizhi_shengyu);
		UIWindows.getInstance().m_fuben.open((byte) 3);
	}

	/**
	 * 玩家是否活着
	 * 
	 * @return true没死,false死亡
	 */
	public boolean isAliveStatus()
	{
		if (m_status != ACTOR_STATUS_DEAD) {
			return true;
		}
		DWGameManager.getInstance().showToast("您已经死亡!", Toast.LENGTH_SHORT);
		return false;
	}

	public void keyAnyStopOther()
	{
		clearAutoAttack();
		clearPathfinding();
		// clearFollowTarget();
		// stopMacro();
	}

	// 外显部件索引
	public static final int ANIM_RIDE = 0;
	public static final int ANIM_LOWER = 1;
	public static final int ANIM_UPPER = 2;
	public static final int ANIM_HEAD = 3;
	public static final int ANIM_WEAPON = 4;
	public static final int ANIM_EFFECT1 = 5; // 宝石
	public static final int ANIM_EFFECT2 = 6; // 武器强化

	/**
	 * 获得完整的动画资源名
	 * 
	 * @param sex
	 * 性别
	 * @param partInx
	 * 部位索引
	 * @param url
	 * @return
	 */
	public String getFigureName(int partInx, String url)
	{
		Tools.debugPrintln("partInx" + partInx + "角色url:" + url);
		if (m_vocation == 0) {
			Tools.debugPrintln("getFigureName 角色职业错误--角色：" + m_name);
			return null;
		}
		StringBuffer buff = new StringBuffer();
		switch (partInx) {
			case ANIM_HEAD:
			case ANIM_UPPER:
			case ANIM_LOWER:
				if (url == null || url.length() < 1) {
					url = STR_FIGURE_DEFAULT[m_vocation];
				}
				buff.append(STR_ZHU);
				buff.append(m_sex == 1 ? STR_NAN : STR_NV);
				buff.append(url);
				buff.append(STR_PART[partInx - ANIM_LOWER]);
				break;
			default:
				if (url == null || url.length() < 1)
					return null;
				buff.append(url);
				break;
		}
		return buff.toString();
	}

	public static final String STR_ZHU = "zhu_";
	public static final String STR_NAN = "nan_";
	public static final String STR_NV = "nv_";

	/**
	 * 角色形象部位名
	 */
	public static final String[] STR_PART = { "_ku", "_yi", "_tou" };

	/**
	 * 角色默认形象资源名
	 */
	public static final String[] STR_FIGURE_DEFAULT = { "jianke_1", "jianke_1",
			"daoke_1", "fashi_1" };

	/** 创建角色动画 */
	public void initRoleAnims(Resource resource, String[] urls)
	{
		if (urls != null && urls.length > 0) {
			m_anims = new Animation[urls.length];
			m_refsResHead = new ResHead[urls.length];
			for (int i = 0; i < urls.length; i++) {
				urls[i] = getFigureName(i, urls[i]);
				if (urls[i] == null || urls[i].length() == 0
						|| urls[i].equals("")) {
					m_refsResHead[i] = null;
					m_anims[i] = null;
					continue;
				}
				m_refsResHead[i] = new ResHead();
				m_refsResHead[i].m_type = DWSerializableFactory.RESOURCE_TYPE_ANIM;
				m_refsResHead[i].m_url = new StringBuffer()
						.append(DWSerializableFactory.DIR_ANIM).append(urls[i])
						.append(DWSerializableFactory.EXTENSION_ANIM)
						.toString();
				m_refsResHead[i].m_version = 1;
				m_anims[i] = (Animation) (ResourceManager.getInstance()
						.loadResource(resource, m_refsResHead[i]));
			}

			m_anim = m_anims[Role.ANIM_HEAD];
			setActionFrame(2, 0);
		}
	}

	// //////////////////////////////////////////////////////////
	// // 同屏相关
	public void recvSceneAdd(DataInputStream dis)
	{
		try {
			m_faction = dis.readByte();
			m_actor_flag = dis.readByte();
			m_vocation = dis.readByte();
			m_sex = dis.readByte();
			m_name = dis.readUTF();
			m_lv = dis.readShort();
			m_status = dis.readByte();
			m_action = dis.readInt();
			m_underAttack_range = dis.readShort();
			m_hp = dis.readInt();
			m_hpMax = dis.readInt();
			m_mp = dis.readInt();
			m_mpMax = dis.readInt();
			m_anger = dis.readByte();
			m_angerMax = dis.readByte();

			int resCount = dis.readByte();
			if (m_refsResHead == null) {
				m_refsResHead = new ResHead[resCount];
			}
			if (m_anims == null) {
				m_anims = new Animation[resCount];
			}

			String[] urls = new String[resCount];
			String temp;
			for (int i = 0; i < resCount; i++) {
				temp = dis.readUTF();
				if (temp.length() == 0) {
					temp = null;
				}
				urls[i] = temp;
			}

			int speed = dis.readShort();
			setAttr(Attribute.SPEED, speed);
			m_velocity = speed / (float) DWGameManager.FRAME_PER_SECOND;
			m_posX = dis.readShort();
			m_posY = dis.readShort();

			m_actionIDNow = dis.readShort();

			m_family_name = dis.readUTF();
			m_vip_lv = dis.readByte();
			m_wanted_type = dis.readByte();
			m_appellation_color = dis.readByte();
			m_appellation = dis.readUTF();
			byte zq_type = dis.readByte();

			for (int i = 0; i < resCount; i++) {
				String resName = getFigureName(i, urls[i]);
				if (resName == null) {
					m_refsResHead[i] = null;
					m_anims[i] = null;
					continue;
				}
				int resType = DWSerializableFactory.RESOURCE_TYPE_ANIM;
				String resUrl = new StringBuffer()
						.append(DWSerializableFactory.DIR_ANIM).append(resName)
						.append(DWSerializableFactory.EXTENSION_ANIM)
						.toString();
				int resVersion = 1;
				ResHead head = new ResHead(resType, resUrl, resVersion);
				m_refsResHead[i] = head;
				if (m_anims[i] == null
						|| !m_anims[i].m_resHead.equals(m_refsResHead[i])) {
					m_anims[i] = (Animation) (ResourceManager.getInstance()
							.loadResource(
									DWGameManager.getInstance().m_resourceDynamic,
									m_refsResHead[i]));
				}
			}
			m_anim = m_anims[Role.ANIM_HEAD];

			// 坐骑相关
			if (m_refsResHead[Role.ANIM_RIDE] == null) {
				m_isride = false;
				m_ride = null;
			}
			else {
				m_isride = true;
				if (m_ride != null) {
					m_ride.dispose();
					m_ride = null;
				}
				m_ride = new Actor(m_anims[Role.ANIM_RIDE]);
			}

			if (m_refsResHead.length > Role.ANIM_EFFECT1) {
				// 角色身上的宝石光效
				if (m_refsResHead[Role.ANIM_EFFECT1] == null) {
					m_effect1 = null;
				}
				else {
					if (m_effect1 != null) {
						m_effect1.dispose();
						m_effect1 = null;
					}
					m_effect1 = new Actor(m_anims[Role.ANIM_EFFECT1]);
				}
			}

			if (m_refsResHead.length > Role.ANIM_EFFECT2) {
				// 角色身上的武器强化光效
				if (m_refsResHead[Role.ANIM_EFFECT2] == null) {
					m_effect2 = null;
				}
				else {
					if (m_effect2 != null) {
						m_effect2.dispose();
						m_effect2 = null;
					}
					m_effect2 = new Actor(m_anims[Role.ANIM_EFFECT2]);
				}
			}

			clearFlex();

			activate();

			if (m_status == Role.ACTOR_STATUS_DEAD) {
				setAction(Role.ACTION_DEAD * Role.DIRECT_NUM, 0, 0, false, true);
				setFrame(m_anim.m_actions[Role.ACTION_DEAD * Role.DIRECT_NUM].length - 1);
			}
			else {
				stay(m_direct);
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void recvSceneUpdatePosition(DataInputStream dis)
	{
		try {
			short x = dis.readShort();
			short y = dis.readShort();
			activate();
			addFlex(new Point(x, y));
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void recvSceneUpdateData(DataInputStream dis)
	{
		try {
			m_hp = dis.readInt();
			m_hpMax = dis.readInt();
			m_mp = dis.readInt();
			m_mpMax = dis.readInt();
			m_anger = dis.readByte();
			m_angerMax = dis.readByte();

			setAttr(Attribute.MAX_HP, m_hpMax);
			setAttr(Attribute.MAX_MP, m_mpMax);

			// 重置大招
			if (this == m_scene.m_controlledActor && m_anger == 0) {
				UIWindows.getMain().resetDazhao();
			}

			// 更新自身头像以及目标头像
			if (this == m_scene.m_controlledActor) {
				UIWindows.getMain().updateMyHead();
			}
			else if (this == m_scene.m_controlledActor.m_targetActor) {
				UIWindows.getMain().updateTargetHead();
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void recvSceneUpdateFigure(DataInputStream dis)
	{
		try {
			int resCount = dis.readByte();// 读资源个数
			String[] urls = new String[resCount];
			String temp;

			for (int i = 0; i < resCount; i++) {
				temp = dis.readUTF();
				if (temp.length() == 0) {
					temp = null;
				}
				urls[i] = temp;// 动画URL
			}

			int speed = dis.readShort();
			setAttr(Attribute.SPEED, speed);
			m_velocity = speed / (float) DWGameManager.FRAME_PER_SECOND;

			m_family_name = dis.readUTF();
			m_vip_lv = dis.readByte();
			m_wanted_type = dis.readByte();
			m_appellation_color = dis.readByte();
			m_appellation = dis.readUTF();
			byte zq_type = dis.readByte();

			for (int i = 0; i < resCount; i++) {
				String resName = getFigureName(i, urls[i]);
				if (resName == null) {
					m_refsResHead[i] = null;
					m_anims[i] = null;
					continue;
				}
				int resType = DWSerializableFactory.RESOURCE_TYPE_ANIM;
				String resUrl = new StringBuffer()
						.append(DWSerializableFactory.DIR_ANIM).append(resName)
						.append(DWSerializableFactory.EXTENSION_ANIM)
						.toString();
				int resVersion = 1;
				ResHead head = new ResHead(resType, resUrl, resVersion);
				m_refsResHead[i] = head;
				if (m_anims[i] == null
						|| !m_anims[i].m_resHead.equals(m_refsResHead[i])) {
					m_anims[i] = (Animation) (ResourceManager.getInstance()
							.loadResource(
									DWGameManager.getInstance().m_resourceDynamic,
									m_refsResHead[i]));
				}
			}
			m_anim = m_anims[Role.ANIM_HEAD];

			// 坐骑相关
			if (m_refsResHead[Role.ANIM_RIDE] == null) {
				m_isride = false;
				m_ride = null;
			}
			else {
				m_isride = true;
				if (m_ride != null) {
					m_ride.dispose();
					m_ride = null;
				}
				m_ride = new Actor(m_anims[Role.ANIM_RIDE]);
			}

			if (m_refsResHead.length > Role.ANIM_EFFECT1) {
				// 角色身上的宝石光效
				if (m_refsResHead[Role.ANIM_EFFECT1] == null) {
					m_effect1 = null;
				}
				else {
					if (m_effect1 != null) {
						m_effect1.dispose();
						m_effect1 = null;
					}
					m_effect1 = new Actor(m_anims[Role.ANIM_EFFECT1]);
				}
			}

			if (m_refsResHead.length > Role.ANIM_EFFECT2) {
				// 角色身上的武器强化光效
				if (m_refsResHead[Role.ANIM_EFFECT2] == null) {
					m_effect2 = null;
				}
				else {
					if (m_effect2 != null) {
						m_effect2.dispose();
						m_effect2 = null;
					}
					m_effect2 = new Actor(m_anims[Role.ANIM_EFFECT2]);
				}
			}

			if (m_status == Role.ACTOR_STATUS_DEAD) {
				setAction(Role.ACTION_DEAD * Role.DIRECT_NUM, 0, 0, false, true);
				setFrame(m_anim.m_actions[Role.ACTION_DEAD * Role.DIRECT_NUM].length - 1);
			}
			else {
				stay(m_direct);
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void recvSceneUpdateStatus(DataInputStream dis)
	{
		try {
			m_status = dis.readByte();
			if (isDead()) {
				// dealDead();
				if (this == m_scene.m_controlledActor.m_targetActor) {
					m_scene.setTargetActor(null);
					m_scene.m_controlledActor.clearAutoAttack();
				}
				else if (this == m_scene.m_controlledActor) {
					UIHook.closeHook();
					breakAutoAttack();
				}
			}
			else {
				stay(m_direct);
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void recvSceneUpdateAction(DataInputStream dis)
	{
		try {
			m_action = dis.readInt();
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	// // 同屏相关
	// //////////////////////////////////////////////////////////

	// ////////////////////////////////////////////
	// 婚姻
	// ///////////////////////////////////////////
	public long m_spouseID = 0;// 配偶ID
	public String m_spouseName = "";// 配偶姓名
	public byte m_marriage_lv = 0;// 婚姻等级
	public long m_marriage_exp = 0;// 夫妻当前友好度
	public long m_marriage_maxExp = 0;// 夫妻升级友好度
	public byte m_marriage_yuanbao = 0;// 元宝充值提出
	public byte m_marriage_jinbi = 0;// 金币掉落提成
	public boolean m_marriage_transfer = false;// 夫妻有无传送技能
	public long m_marriage_CD = 0;// 传送技能冷却时间
	public long m_marriage_CDStar = 0;

	/**
	 * 婚姻信息
	 * 
	 * @param dis
	 */
	public void recvMarriageMessage(DataInputStream dis)
	{
		Tools.debugPrintln("---------------------婚姻信息");
		try {
			byte state = dis.readByte();
			Tools.debugPrintln("MarriageMessage state=" + state);
			if (state == 1) {
				for (int i = 0; i < 2; i++) {
					long id = dis.readLong();
					String name = dis.readUTF();
					if (id != m_gameId) {
						m_spouseID = id;
						m_spouseName = name;
					}
				}
				Tools.debugPrintln("m_spouseName=" + m_spouseName);
				m_marriage_lv = dis.readByte();
				Tools.debugPrintln("m_marriage_lv=" + m_marriage_lv);
				m_marriage_exp = dis.readLong();
				Tools.debugPrintln("m_marriage_exp=" + m_marriage_exp);
				m_marriage_maxExp = dis.readLong();
				Tools.debugPrintln("m_marriage_maxExp=" + m_marriage_maxExp);

				m_marriage_yuanbao = dis.readByte();
				Tools.debugPrintln("m_marriage_yuanbao=" + m_marriage_yuanbao);
				m_marriage_jinbi = dis.readByte();
				Tools.debugPrintln("m_marriage_jinbi=" + m_marriage_jinbi);

				byte isTransfer = dis.readByte();
				Tools.debugPrintln("isTransfer=" + isTransfer);
				m_marriage_transfer = (isTransfer == 0 ? false : true);

				m_marriage_CD = dis.readLong();
				Tools.debugPrintln("m_marriage_CD=" + m_marriage_CD);
				if (m_marriage_CD > 0)
					m_marriage_CDStar = System.currentTimeMillis() / 1000;
				else
					m_marriage_CDStar = 0;
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 婚姻等级
	 * 
	 * @param dis
	 */
	public void recvMarriageLv(DataInputStream dis)
	{
		Tools.debugPrintln("---------------------婚姻等级");
		try {
			m_marriage_lv = dis.readByte();
			Tools.debugPrintln("m_marriage_lv=" + m_marriage_lv);
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 夫妻友好度
	 */
	public void recvMarriageExp(DataInputStream dis)
	{
		try {
			Tools.debugPrintln("------------夫妻友好度");
			m_marriage_exp = dis.readLong();
			Tools.debugPrintln("m_marriage_exp=" + m_marriage_exp);
			m_marriage_maxExp = dis.readLong();
			Tools.debugPrintln("m_marriage_maxExp=" + m_marriage_maxExp);
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 夫妻传送冷却时间
	 */
	public void recvTransferCD(DataInputStream dis)
	{
		try {
			m_marriage_CD = dis.readLong();
			m_marriage_CDStar = System.currentTimeMillis() / 1000;
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 接收道具使用成功失败
	 * */
	public void recvItemConsumeUsedOK(DataInputStream dis)
	{
		try {
			byte state = dis.readByte();
			int cdType = dis.readByte();
			String key = String.valueOf(cdType);
			long curTime = System.currentTimeMillis();
			Long[] value = null;
			if (m_item_cd.containsKey(key)) {// 是否当前MAP里有此类型道具
				value = m_item_cd.get(key);
				if (state == 1) {
					value[0] = Long.valueOf(curTime);
					m_item_cd.put(key, value);
				}
				else {
					m_item_cd.remove(key);
				}
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 读取摆摊栏信息
	 */
	public void recvColumnShop(DataInputStream dis)
	{
		try {
			byte state = dis.readByte();
			if (state == 1) {
				byte nowsize = dis.readByte();
				byte maxsize = dis.readByte();
				COLUMN_MAX_SIZE[Cell.TYPE_COLUMN_SHOP] = maxsize;

				Tools.debugPrintln("最大数量"
						+ COLUMN_MAX_SIZE[Cell.TYPE_COLUMN_SHOP]);

				m_column_shop = null;
				m_column_shop = new Cell[nowsize];
				for (int i = 0; i < nowsize; i++) {
					m_column_shop[i] = new Cell(Cell.TYPE_COLUMN_SHOP, i);
				}
				recvColumnUpdataShop(dis);
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void recvColumnUpdataShop(DataInputStream dis)
	{
		try {
			// 读当前有无道具被存在栏里
			if (m_column_shop == null) {
				return;
			}
			int num = 0;
			for (Cell c : m_column_shop) {
				if (c != null) {
					num++;
				}
			}
			byte size = dis.readByte();
			if (size > 0 && size <= num) {
				for (int i = 0; i < size; i++) {
					long guid = dis.readLong();
					int itemnum = dis.readInt();
					int itemmoney = dis.readInt();
					String itemname = dis.readUTF();

					SellItem sellitem = new SellItem();
					sellitem.m_num = itemnum;
					sellitem.m_UntiPrice = itemmoney;
					sellitem.m_name = itemname;

					Item item = getItemByGuidForAllColumn(guid);
					if (item != null) {
						item = item.Clone();
						item.m_num = itemnum;
						item.m_sell = sellitem;
					}
					m_column_shop[i].m_item = item;

				}
			}
		}
		catch (Exception e) {
			// TODO: handle exception
		}
	}

	/**
	 * 更新师徒信息
	 * @param dis
	 */
	public void recvShituMessage(DataInputStream dis)
	{
		try {
			m_shitu_guanxi = dis.readUTF();
		}
		catch (Exception e) {
		}
	}

	/**
	 * 接收创建栏命令
	 * */
	public void recvVipAutoRepairEquip(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_修理);
		try {
			byte state = dis.readByte();//0成功 1VIP等级 2修理费不足
			String temp = null;
			switch (state) {
				case 0:
					temp = "自动修理装备成功！";
					break;
				case 1:
					break;
				case 2:
					temp = "修理费用不足，修理失败！";
					break;
			}
			if (temp != null) {
				DWGameManager.getInstance().addSystemInfo(DWGameManager.SYSTEM_INFO_TYPE_B, temp);
			}
		}
		catch (Exception e) {
			// TODO: handle exception
		}
	}
}
